C# math.round()使用

math.round()使用的使用守则为:"四舍六入五考虑,五后非零就进一,五后皆零看奇偶,五前为偶应舍去,五前为奇要进一"

public static decimal Round(decimal d, int decimals, MidpointRounding mode);//标准的四舍五入计算
public static double Round(double value, int digits, MidpointRounding mode);

范例:double bb = 1.525;

 double th = Math.Round(bb, 2);//得出来的值为1.52

 double tr = Math.Round(bb, 2, MidpointRounding.AwayFromZero);//得到值为1.53

你可能感兴趣的:(C#基础)