3

Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number

Hello

I have money value like that

    12345
    123456
    1234567
    1234567,89

What i want is formated like this.

12,345
123,456
1,234,567
1,234,567, 89

How can i do that with String.Format ?

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

2 Answers2

8
String.Format("{0:c}");

This will format your number like currency based on the client's locale configuration.

If your client's locale is in Europe it'll come out $12.134,45 because that's how it's done over there.

This is the preferred method of currency formatting, if you want to specifically just get the comma's and no $ you'll probably have to do it using "{0:#,##0}" or something along those lines.

Aren
  • 54,668
  • 9
  • 68
  • 101
  • 2
    +1. Usual reminder - there are cultures that don't have groups separator too. If you explicitly need format with , as "groups separator" pass specific culture (i.e. "en-US" to String.Format). – Alexei Levenkov Mar 24 '11 at 23:02
1

Cool new way...

gt124
  • 1,238
  • 13
  • 23