可能的重复:
使用字符串格式显示最多 2 位小数或简单整数 https://stackoverflow.com/questions/6951335/using-string-format-to-show-decimal-upto-2-places-or-simple-integer
如何设置小数点后两位? https://stackoverflow.com/questions/13284682/how-to-set-decimal-point-in-2-decimal-places
我认为有 Price 字段。它有以下值2.5 and 44.
我想显示这个值2.50 and 44.00
我使用下面的代码
@{decimal prolistprice = decimal.Parse(item.OtherFields["Price"].ToString());}
[email protected] /cdn-cgi/l/email-protection(prolistprice, 2, MidpointRounding.AwayFromZero)
其中item.OtherFields["price"] is a object
我将其转换为字符串,然后转换为十进制
但 Math.round 不起作用,它只显示 2.5 和 44..
谁能帮忙这个
Math.Round
就是这样做的——圆形。
格式化您可能使用的号码.ToString(formatString)
像这样:
item.OtherFields["price"].ToString("0.00")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)