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 ?
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 ?
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)