如何将小数点后舍入到小数点后两位? [英] How do I round a decimal to 2 decimal places?

查看:101
本文介绍了如何将小数点后舍入到小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有此代码:

while(rdr.Read())
{
gotPrice =(rdr.GetDecimal(0));
}
rdr.Close();
< BR>< BR> ....但是在分配变量gotPrice之前,我不知道如何正确地将结果四舍五入到小数点后两位.

while (rdr.Read())
{
gotPrice = (rdr.GetDecimal(0));
}
rdr.Close();
 
 
....but I can't work out how to properly round the result to 2 decimal places before assigning the variable gotPrice?

我得到这个例子:54.9700

I get this as example: 54.9700

我想要gotPrice = 54.97

and I'd like gotPrice = 54.97

感谢您的时间

Thanks for your time

推荐答案

尝试gotPrice = Math.Round(54.9700,2);

Try gotPrice = Math.Round(54.9700,2);

我希望这会有所帮助.


这篇关于如何将小数点后舍入到小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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