0
votes

How can I display decimals with commas instead of decimal with dot in C#.

I got this problem while I have to enter decimal with comma format and I make my calculation but in the browsers I see numbers with dot !

2

2 Answers

4
votes

You can create a CultureInfo and specify that decimal separator will be ,:

var info = CultureInfo.InvariantCulture.Clone() as CultureInfo;
info.NumberFormat.NumberDecimalSeparator = ",";

double n = 123.456;
Console.WriteLine(n.ToString(info));

Output:

"123,456"
2
votes

It depends on you culture. If you specify the culture that uses comma all decimals wil be displayed with ",". If you need dot, choose the culture that uses "."