c# Double保留小数点位数

  math.round():

  将值舍入到最接近的整数或指定的小数位数。

(1)round(double): 将双精度浮点值舍入为最接近的整数。

(2)round(double,Int32):将双精度浮点值舍入到指定精度。

public static double round(double value, int digits)

其中:value是要舍入的双精度浮点数;digits返回值中的小数位数(精度),为0到15之间。

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

原则:四舍六入五取偶

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据