【发布时间】:2010-11-13 21:12:35
【问题描述】:
我需要将十进制数字格式化为货币,但我不希望在此过程中进行任何舍入。
例如(示例文化是美国)
Dim money = 1234.556789D
money.ToString("C") ' Yields $1,234.56 (notice the rounding & truncating)
money.ToString("C99") ' Yields $1,234.556789000000000000....0 -- close but not perfect, those trailing zeros are unwanted.
' I want something that would result in this...
money.ToString("??") ' Yields $1,234.56789
' likewise....
money = 0.1D
money.ToString("??") ' Yields $0.10 (notice that it at least matches the culture's currency format -- two decimal places)
假设此应用程序的所有用户都将使用 en_US 规则,我可以将其设为“??”是硬编码的东西,例如 "$#,##0.00#################################### ##########################”——但这让我的胃翻腾。是否有一种内置方法来完成我所追求的?
【问题讨论】:
-
我已经浏览了大约 20 分钟的帮助文档,但一无所获。对不起。
-
感谢您的宝贵时间 Greg。抱歉,搜索让您(和我)空手而归。我想有这样的需求不是很“正常”,这意味着框架不会自然地支持这个特性。哦,好吧,如下所述,我最终推出了自己的解决方案,直到微软认为它足够棒/有用,可以直接融入框架;)
标签: .net currency string-formatting