首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

java的四舍五入的有关问题

2012-09-02 
java的四舍五入的问题(new DecimalFormat(#.00)).format(5.625) 5.62 0.005被舍掉了(new DecimalForma

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单进双不进????

热点排行