1

Trying to format a number 5620000 to $5,620,000

string html = string.Format("$ {0:n0}", 5620000)

Is it possible to do with string.Format function ?

Uwe Keim
  • 38,279
  • 56
  • 171
  • 280
Govind Samrow
  • 9,455
  • 13
  • 50
  • 85

1 Answers1

2

You can use the overload of ToString() which takes an IFormatProvider as argument and specify that the number is currency.

var value = 5620000;
value.ToString("C", new System.Globalization.CultureInfo("en-US"))

EDIT

As @Uwe Keim pointed out you can also use the String.Format() overload that does this:

String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", 5620000)
RePierre
  • 9,112
  • 2
  • 21
  • 36
  • 1
    `String.Format` also has an overload with `IFormatProvider `, e.g. [this one](https://msdn.microsoft.com/en-us/library/dn906224(v=vs.110).aspx). – Uwe Keim Jul 12 '17 at 13:34