如何仅显示最多2个小数位的值 [英] How to display values only upto 2 decimal places
问题描述
我有一个类型为money的表格列"Amount".当我通过存储过程检索其值时,它最多返回小数点后4位的值(由于是money类型).我希望该值最多保留两位小数,并且希望它在代码中进行处理.如何将数值四舍五入到小数点后两位.谢谢
I have a table column "Amount" of type money. When I am retrieving its value through a store procedure, it returns the value upto 4 decimal places(because of type money). I want the value upto two decimal places and I want it to handle in the code. How will I do it by rounding off the value to 2 decimal place. Thanks
推荐答案
好吧,我尝试了一下,并获得了正确的结果.
Well, I tried it and got the correct result.
下面是我使用的代码:
funding.amount= Math.Round(decimal.Parse(dr["Amount"].ToString()), 2).ToString();
//由于数量是字符串类型,因此我使用了上面的代码.我们还可以使用以下代码:
//since the amount was of string type, therefore I used the above code. we can also use the below code:
decimal.Round(yourValue, 2, MidpointRounding.AwayFromZero);
http://msdn.microsoft.com/en-us/library/9s0xa85y.aspx
这篇关于如何仅显示最多2个小数位的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!