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
  • 39,551
  • 56
  • 175
  • 291
Govind Samrow
  • 9,981
  • 13
  • 53
  • 90

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,358
  • 2
  • 20
  • 37
  • 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