0

I want to show number with comma. I am getting like 20.85 But i need like 20,85. Note: (i dont have web.config in my project) can we create another class and define cost culture(localization) please suggest me code for this .i am new to c# and i am fresher . please help me.

[DisplayName("Cost")]

public decimal Value { get; set; }

I getting this:

20.85

But I want this instead:

20,85
abolfazl sadeghi
  • 2,277
  • 2
  • 12
  • 20

1 Answers1

0

There are many ways to implement that.

By changing culture info at runtime:

System.Globalization.CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator = ",";

Or you can change value format:

 decimal value = 20.85M;
 NumberFormatInfo formatInfo = new NumberFormatInfo();
 formatInfo.NumberDecimalSeparator = ",";
 string y = string.Format(formatInfo,"{0:###0.##}", value);
 Console.WriteLine("value: " + y); // value: 20,85
 Console.ReadKey();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459