Round to 2 decimal places
Possible Duplicate:
Round a double to 2 significant figures after decimal point
I know that there are plenty of examples on how to round this kind numbers. But could someone show me how to round double, to get value that I can display as a String and ALWAYS have 2 decimal places?
你可以使用String.format("%.2f", d)
,你的double会自动舍入。
一个简单的方法来做到这一点:
Double d;
Int i;
D+=0.005;
i=d*100;
Double b = i/100;
String s = b.toString():
链接地址: http://www.djcxy.com/p/21366.html
上一篇: 什么是浮点/舍入错误的简单例子?
下一篇: 舍入到2位小数