[学习笔记]Math.Round

MSDN 对此方法:
public static decimal Round(
decimal d,
int decimals
)

的解说是:

The decimals parameter specifies the number of fractional digits in the return value and ranges from 0 to 28. If decimals is zero, an integer is returned.
If the value of the digits in d to the right of the decimals position is halfway between the digit in position decimals, that digit is rounded up if it is odd, or left unchanged if it is even. If the precision of d is less than decimals, d is returned unchanged.

Sample:
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(4.34, 1); // Returns 4.3
Math.Round(4.35, 1); // Returns 4.4
Math.Round(4.36, 1); // Returns 4.4
就是说遇到最后一位5的时候, 都让它前面的那位数字变成偶数(如果是偶数就不改变)

posted @ 2008-05-29 10:44  Stanley.Luo  阅读(390)  评论(0编辑  收藏  举报