简体   繁体   English

如何在C#中将int格式化为货币?

[英]How to format an int as currency in C#?

I want to format an int as a currency in C#, but with no fractions. 我想在C#中将int格式化为货币,但没有分数。 For example, 100000 should be "$100,000", instead of "$100,000.00" (which 100000.ToString("C") gives). 例如,100000应为“$ 100,000”,而不是“$ 100,000.00”(100000.ToString(“C”)给出)。

I know I can do this with 100000.ToString("$#,0"), but that's $-specific. 我知道我可以使用100000.ToString(“$#,0”)执行此操作,但这是$ -specific。 Is there a way to do it with the currency ("C") formatter? 有没有办法用货币(“C”)格式化器?

使用格式“C0”。

Possible to use n0 which provide commas like 1,234. 可以使用提供1,234等逗号的n0。 Currency sign won't be there 货币符号不会出现

try 尝试

using System.Globalization
@string.Format(new CultureInfo("en-IN"), "{0:c}", moneyvalue)

wil show the format in Rs. 将显示Rs中的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM