读书人

java的四舍五入的有关问题

发布时间: 2012-09-02 21:00:34 作者: rapoo

java的四舍五入的问题
(new DecimalFormat("#.00")).format(5.625) = 5.62 0.005被舍掉了
(new DecimalFormat("#.00")).format(5.625000001) = 5.65 0.0050000001进位了
(new DecimalFormat("#.000")).format(5.6255) = 5.626 0.0005进位了

为啥???

http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
里记载

The value has three digits to the right of the decimal point, but the pattern has only two. The format method handles this by rounding up.

说是rounding up的??

java也搞的是4舍6入,逢5单进双不进????

读书人网 >软件架构设计

热点推荐