你怎么圆了许多在C#小数点后两位? [英] How do you round a number to two decimal places in C#?

查看:211
本文介绍了你怎么圆了许多在C#小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做,使用 Math.Round 函数

推荐答案

下面是一个例子:

decimal a = 1.994444M;

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

decimal b = 1.995555M;

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

您可能也想看看银行家四舍五入/舍入到甚至以下过载:

You might also want to look at bankers rounding / round-to-even with the following overload:

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

还有更多的信息在这里

There's more information on it here.

这篇关于你怎么圆了许多在C#小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆