简体   繁体   中英

How to format an int as currency in C#?

I want to format an int as a currency in C#, but with no fractions. For example, 100000 should be "$100,000", instead of "$100,000.00" (which 100000.ToString("C") gives).

I know I can do this with 100000.ToString("$#,0"), but that's $-specific. Is there a way to do it with the currency ("C") formatter?

使用格式“C0”。

Possible to use n0 which provide commas like 1,234. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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