开发者

How to println double in a readable format?

开发者 https://www.devze.com 2023-04-10 14:44 出处:网络
For example, I want to c开发者_如何学Goalculate this: 4,000,000.0 * 4; and I got this: 1.6E7. What should I do, to got this: 16,000,000.0?? Thx!!Use DecimalFormat as follows:

For example, I want to c开发者_如何学Goalculate this: 4,000,000.0 * 4; and I got this: 1.6E7. What should I do, to got this: 16,000,000.0?? Thx!!


Use DecimalFormat as follows:

double d = 10000000.00;
DecimalFormat dfmt = new DecimalFormat(",000.0");

System.out.println(dfmt.format(d)); // will display 10,000,000.0


Have a look at java.text.DecimalFormat class.


Use NumberFormat or DecimalFormat http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html


You can implement DecimalFormat or String.format("%.2f", someNumber).

0

精彩评论

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