我在 VB.NET 中使用Decimal
来保存货币值。在我的网站上可以为项目添加折扣,该折扣被输入到文本框中,然后在代码隐藏中检索值。
Dim discountValue As Decimal = 0
discountValue = Decimal.Round(Convert.ToDecimal(txtDiscount.Text), 2)
lblDiscount.Text = "£" & discountValue.ToString()
但是,当我在添加折扣后查看标签时,它没有四舍五入到小数点后 2 位。
有什么原因不起作用吗?我在这种方法中做错了什么?
注意:我使用的是 ASP.NET VB.NET,页面包装在更新面板中。
这是因为如果数字*.00
,ToString(( 只是格式化它而不带小数点
更改此行:
lblDiscount.Text = "£" & discountValue.ToString("N2")