开发者

convert value to simple notation from scientific notation in java

开发者 https://www.devze.com 2023-02-17 20:11 出处:网络
When my double value exceed from 7 digits it\'s show value in scientifi开发者_如何转开发c notation. But, i don\'t want scientific notation.

When my double value exceed from 7 digits it's show value in scientifi开发者_如何转开发c notation. But, i don't want scientific notation.

DecimalFormat is one way to do the same but, for that i require to convert value into string. is it possible the same conversion without converting double to string.


DecimalFormat.format(Object) can handle a double without any String involvement.


If you are displaying it, it is a String.

By using DecimalFormat, you are just telling Java how to do the conversion

Without this, it will use the default scientific notation


double d = 123456789.4335;
System.out.println(">> "+new DecimalFormat("#0.###").format(d));
System.out.println(">> "+d);

prints

 >> 123456789.434
 >> 1.234567894335E8
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号