How to insert a comma to left after every 3 digits and show 2 decimal places in c# but using String.Format
Thanks.
How to insert a comma to left after every 3 digits and show 2 decimal places in c# but using String.Format
Thanks.
string a = string.Format("{0:n}", 1234567.123);
result would be 1,234,567.12
Try this, though i just copied it from another question here in SO
String.Format("{0:#,###,###.##}", MyNumber)
Refer to this link: StringFormat int
This question is very old. The new way of doing is using string interpolation as:
var value = 1234567890.106;
Console.WriteLine($"{value:n}");
Try this
int number = 10000000000; string whatYouWant = number.ToString("##,##0");
//You get: 10,000,000,000
var value = 1234567890.106;
Console.WriteLine( String.Format( CultureInfo.InvariantCulture,
"{0:#,#.##}", value ) );
Refer to this in the future:
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx#SpecifierD