1

For my web application I want the prices to have a comma as decimal separator on all my pages of my web application. I managed this by adding these line of codes in the program.cs:

CultureInfo.CurrentCulture = new CultureInfo("nl-NL");
CultureInfo.CurrentUICulture = new CultureInfo("nl-NL");

And when I run my web application, I see the comma as decimal separator. But, when I navigate to a different page, also having prices, the decimal separator has changed into a dot. And when I navigate back to the page where the comma was shown as decimal separator, it now shows a dot as decimal separator as well.

It looks like the comma as decimal separator only works the first time. After that, it goes back to the dot. I cannot figure out why this is happening or how to fix this. Can someone perhaps explain to me what the cause of my issue could be?

Cornelis
  • 1,729
  • 5
  • 23
  • 39
  • https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-6.0&pivots=webassembly – gunr2171 Nov 17 '22 at 22:11

1 Answers1

2

A quick and dirty approach is to also set DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture in program.cs.

var cultureInfo = new CultureInfo("nl-NL");
CultureInfo.CurrentCulture = cultureInfo;
CultureInfo.CurrentUICulture = cultureInfo;
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

Official documentation on localization in Blazor: https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Oh, if I understand it correctly, it was some kind of a threading issue? That makes sense. Thank you for helping out! – Cornelis Nov 18 '22 at 08:08