How to change Locale of .NET Core 3.1?

Viewed 1108

Is there a way to change the locale of .Net Core 3.1? Perhaps via dotnet CLI? Right now it's using , for decimals instead of ..

I'm working on a console application using .Net Core 3.1.

2 Answers

at startup of your application:

System.Threading.Thread.CurrentThread.CurrentCulture 
  = System.Globalization.CultureInfo.GetCultureInfo("en");

or "fr" or "the culture of your choice"

or to go straight to the point (less good to my opinion):

System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyGroupSeparator="";
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator="";
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator=".";
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator=".";

You should do it in Main method just as here:

CultureInfo.CurrentCulture = new CultureInfo("th-TH", false);
CultureInfo.CurrentUICulture = new CultureInfo( "ja-JP", false);

CultureInfo object is prefered way of doing that instead of CurrentThread. Please see Microsoft doc.

Related