新浪博客

负数如何四舍五入?有争议!

2014-02-02 14:10阅读:
-8.5四舍五入后是多少?
以下是不同计算机程序的运算结果
JavaScript:Math.round(-8.5) = -8
Oracle:Select round(-8.5) from dual =-9
Excel:Round(-8.5) = -9
Round意思是进位,进位的方法有很多种。数学上默认使用四舍五入,即5 or greater than 5 Round up,less than 5 Round down.
-8.5要变大,-8>-9,所以正确答案是-8。
一些程序为了减少误差,使用了例如四舍六入五留双(统计学上常用),还有背零进位、向零进位等,所以会有不同答案。
参考资料:http://www.mathsisfun.com/numbers/rounding-methods.html

我的更多文章

下载客户端阅读体验更佳

APP专享