1.
Math.Round(4.4); //Returns 4.0.
Math.Round(4.5); //Returns 4.0.
Math.Round(4.6); //Returns 5.0.
返回值
最接近参数 d 的整数。
如果 d 为两个整数的中值,这两个整数一个为偶数,另一个为奇数,则返回偶数。
说明:此方法的行为遵循 IEEE 标准 754 的第 4 节。这种舍入有时称为就近舍入或银行家舍入。
2.
Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.
参数
d
要舍入的小数。
decimals
返回值中的有效数字位数(精度)。
返回值
精度等于 decimals,最接近 d 的数字。
如果 d 位于两个数字的中间,其中一个为偶数,另一个为奇数,则返回偶数。
如果 d 的精度小于 decimals,则返回 d 而不做更改。
Math.Round(-11.5); //Returns -12
Math.Round(11.5); //Returns 12
Math.Round(3.445, 1); //Returns 3.4.
Math.Round(3.455, 1); //Returns 3.5.
Math.Round(3.465, 1); //Returns 3.5.
Math.Round(3.4452, 2); //Returns 3.45.
Math.Round(3.4552, 2); //Returns 3.46.
Math.Round(3.4652, 2); //Returns 3.47.
四舍六入五成双