简体   繁体   中英

Parsing DecimalFormat to avoid scientific notation

I need parsing a number, String value = "15000000"

Public static String FormatValue(value){
    double formatedValue= Double.parseDouble(value);        

    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');       
    dfs.setGroupingSeparator(' ');
    DecimalFormat df = new DecimalFormat("# ### ### ### ###.##", dfs);
    df.format(valorAformatear);
    return  String.valueOf(formatedValue);  
}   

I need the return value to be "15 000 000.00" BUT, When I call the method returns, "7.5E7", how can I avoid the scientific notation?

You ignored the return of the format method and instead returned the normal conversion to a String using String.valueOf . The format method doesn't change the number; it returns its formatted representation. Also, String.valueOf will use scientific notation if the number is large enough.

Just return what format returns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM