blazordecimalcultureinfoseparator

How to use dot as decimal separator when the current culture is Greek


I would like to change the decimal separator in a Blazor .NET 7 multi-language site when the selected language is Greek.

The numbers are by default changed to comma separated when I change the language to Greek and this cause me troubles in calculations in multiple places of my code.

Any idea how can I do this?


Solution

  • Decimal doesn't came with dot or comma, but when convert to string, it will add dot or comma depending on thread culture. You can add CultureInfo.InvariantCulture when comvert.

                Thread.CurrentThread.CurrentCulture = new CultureInfo("el-GR");
                decimal d = 5.50m;
                string withComma = d.ToString();
                string withDot = d.ToString(CultureInfo.InvariantCulture);
                Console.WriteLine(withComma);
                Console.WriteLine(withDot);
    

    output
    enter image description here