2

How to insert a comma to left after every 3 digits and show 2 decimal places in c# but using String.Format

Thanks.

mihai
  • 4,592
  • 3
  • 29
  • 42
Naveen Sharma
  • 89
  • 1
  • 5

5 Answers5

4
        string a = string.Format("{0:n}", 1234567.123);        

result would be 1,234,567.12

3

Try this, though i just copied it from another question here in SO

String.Format("{0:#,###,###.##}", MyNumber)

Refer to this link: StringFormat int

Community
  • 1
  • 1
DevEstacion
  • 1,947
  • 1
  • 14
  • 28
  • Welcome to StackOverflow! Please accept my answer if it solves your problem, here's the info you need: How to accept an answer. Please also consider to upvote my answer when you have enough reputation to do so. @Naveen Sharma – DevEstacion Nov 10 '14 at 05:58
1

This question is very old. The new way of doing is using string interpolation as:

var value = 1234567890.106;
Console.WriteLine($"{value:n}");
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
0

Try this

int number = 10000000000; string whatYouWant = number.ToString("##,##0");

//You get: 10,000,000,000

0
        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

Debopam Chanda
  • 161
  • 1
  • 7