开发者

How to println double in a readable format?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜