How to format an int as currency in C#?

29,039

Solution 1

Use format "C0".

Solution 2

Possible to use n0 which provide commas like 1,234. Currency sign won't be there

Solution 3

try

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

wil show the format in Rs.

Share:
29,039
Ken
Author by

Ken

Updated on July 09, 2022

Comments

  • Ken
    Ken almost 2 years

    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?

  • RJB
    RJB over 7 years
    .ToString("C0") or .ToString("C2")... it only took me a second, but if it saves somebody a second....