【发布时间】:2017-06-20 03:42:17
【问题描述】:
在 VS2017 VB.net 网络表单应用程序中,我尝试将一个数字(字符串(“12345.0000”))格式化为“12345.00”格式,即 2 位小数,没有千位分隔符。为此,我使用以下代码行:-
rentalPriceVal = Format(memberPrices.RentalPrice, "0.00")
它返回“0.00”。
我最初有 FormatNumber(memberPrices.RentalPrice, 2),但它添加了一个依赖于语言环境的千位分隔符和十进制标识符。
我也尝试过:memberPrices.RentalPrice.ToString("0.00"),但出现“无法将字符串转换为 IFormatProvider”的错误。
我很茫然。我是否搞砸了语法,有没有更好的方法我还没有遇到过,还是不可能?
谢谢。
【问题讨论】:
-
先把字符串转成数字,再格式化。
-
Format(Val(memberPrices.RentalPrice), "0.00")