在C#中把双数四舍五入到两个小数位?

我想在c#中把双倍的数值四舍五入到小数点后两位,我该怎么做呢?

double inputValue = 48.485;

四舍五入后

inputValue = 48.49;

相关的: https://stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-to-2-decimal-places-for-output-on-a-pa

解决办法

这很有效。

inputValue = Math.Round(inputValue, 2);
评论(2)
Math.Round(inputValue, 2, MidpointRounding.AwayFromZero)
评论(5)

使用Math.Round

value = Math.Round(48.485, 2);
评论(2)