如何将双精度数转换为最接近的整数值?

问题描述:

如何将双精度数转换为最接近的整数?

How do you convert a double into the nearest int?

使用 Math.round( ),可能与 MidpointRounding.AwayFromZero

结合使用,例如:

Math.Round(1.2) ==> 1
Math.Round(1.5) ==> 2
Math.Round(2.5) ==> 2
Math.Round(2.5, MidpointRounding.AwayFromZero) ==> 3