开发者

convert value to simple notation from scientific notation in java

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜