我想用数学来做。圆的函数


当前回答

下面是一些例子:

decimal a = 1.994444M;

Math.Round(a, 2); //returns 1.99

decimal b = 1.995555M;

Math.Round(b, 2); //returns 2.00

你可能还想看看银行家的四舍五入/四舍五入到偶数与以下过载:

Math.Round(a, 2, MidpointRounding.ToEven);

这里有更多的信息。

其他回答

试试这个:

twoDec = Math.Round(val, 2)

下面是一些例子:

decimal a = 1.994444M;

Math.Round(a, 2); //returns 1.99

decimal b = 1.995555M;

Math.Round(b, 2); //returns 2.00

你可能还想看看银行家的四舍五入/四舍五入到偶数与以下过载:

Math.Round(a, 2, MidpointRounding.ToEven);

这里有更多的信息。

Math.Floor(123456.646 * 100) / 100 会返回123456.64吗

字符串a = "10.65678";

decimal d = Math.Round(Convert.ToDouble(a.ToString()),2)

您应该能够使用Math指定要舍入的位数。轮(YourNumber, 2)

你可以在这里阅读更多。