Math.Round和四舍五入

简介:

Math.Round方法并不是像想象中的四舍五入, 可以从下面的输出结果看出来:

Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.

Math.Round默认实际的方式是“四舍六入法”。

世界上的许多国家已广泛采用“四舍六入法”。我国国家科委于1955年就作了推荐。“四舍 六入法”可以概括为:“四舍六入五考虑,五后非零就进一,五后皆零看奇偶,五前为偶应舍去,五前为奇要进一。

 

想要达到我们平时使用的四舍五入,需要这样:

Math.Round(3.45,   1,   MidpointRounding.AwayFromZero)


Creative Commons License

本文基于署名 2.5 中国大陆许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名justrun(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言


本文转自JustRun博客园博客,原文链接:http://www.cnblogs.com/JustRun1983/archive/2012/06/14/2549877.html,如需转载请自行联系原作者

相关文章
|
4月前
round() 函数:对一个数进行四舍五入
round() 函数:对一个数进行四舍五入
58 0
|
1月前
|
SQL 关系型数据库 MySQL
ROUND
ROUND
28 5
|
12月前
|
C++
C++ 多种取整函数的使用和区别: ceil() floor() round() trunc() rint() nearbyint()
C++ 多种取整函数的使用和区别: ceil() floor() round() trunc() rint() nearbyint()
149 0
Math.ceil()
Math.ceil()
97 0
Math.pow()
Math.pow()
52 0
4.2、Math数学对象(floor、random、sqrt、pow、abs)
4.2、Math数学对象(floor、random、sqrt、pow、abs)
131 0
|
Python
Python浮点数转整数int、round、ceil、floor
Python浮点数转整数int、round、ceil、floor
119 0
|
人工智能
Next Round
Next Round
77 0
Next Round
|
安全 iOS开发
iOS开发-math.h/ceil/floor/round
https://blog.csdn.net/acmicpc123/article/details/50280097
115 0
iOS开发-math.h/ceil/floor/round
Math.round(11.5) 等于多少?Math.round(-11.5)等于多少?
Math.round(11.5)的返回值是12,Math.round(-11.5)的返回值是-11。四舍五入的原理是在参数上加0.5然后进行下取整。
1572 0