0

It seems that Blazor WebAssembly applications format currencies as "123,45 $" for the es-US locale, while console or native server .NET format as "$123.45".

I would expect the "$123.45" currency format for es-US in both cases.

Which one of these is correct for "es-US"? And, in either case, what is the right way to let Microsoft know about this discrepancy (or, is the discrepancy intentional for some reason)?

To clarify, the same code below produces different results when running on the same machine depending on whether you're in a Blazor WebAssembly project or a console app project:

var culture = new CultureInfo("es-US");
var amt = 123.45M;
Console. WriteLine(amt. ToString("C"), culture);

Running this JS in a local web page also gives "123.45" with the period:

var amt = 123.45;
alert(amt.toLocaleString("es-US", { minimumFractionDigits: 2 });

This page seems to confirm the "$123.45" format is right for es-US, and I'd assume that browser/vanilla JS and server/native .NET are more likely to be correct than Blazor, and those three agree (also W3 schools & dotnetfiddle): https://www.localeplanet.com/icu/es-US/index.html

Patrick87
  • 27,682
  • 3
  • 38
  • 73
  • 1
    You are using a Spanish US. This is the english US : https://www.localeplanet.com/icu/en-US/index.html – jdweng Aug 02 '23 at 14:44
  • @jdweng I know, I think both en-US and es-US should format as "$123.45" and they both do, EXCEPT Blazor WebAssembly which formats as "123.45 $" – Patrick87 Aug 02 '23 at 14:49
  • Maybe you have right to left set : https://blazor.syncfusion.com/documentation/common/right-to-left – jdweng Aug 02 '23 at 14:59
  • @jdweng I don't see RTL being set anywhere and am not using SyncFusion, this is just a vanilla Blazor client app/website. Would enabling RTL also explain the comma vs period as the decimal separator? I think 123.45 $ (but with the Euro sign) is correct for the es-ES locale, RTL or no... – Patrick87 Aug 02 '23 at 15:24
  • (I see my first comment has a typo, Blazor formats as 123,45 $ with a comma, not a period). – Patrick87 Aug 02 '23 at 15:26
  • The comma verses period is the culture which also affects the RTL. See https://stackoverflow.com/questions/75993127/impossible-to-change-the-culture-at-runtime-with-blazor-server – jdweng Aug 02 '23 at 16:01
  • Blazor is (should be) using the region of the web browser user. A native or server app (unless specifically provided for in the app's code) is using the region of the machine where the code is running. The issue is the problem of relying on the default ambient region/locale instead of being explicit what region/locale you're using to format with, and controlling where that locale comes from and use the right source for that information that is appropriate for the application. – Paul Dempsey Aug 02 '23 at 17:34
  • Another factor is potentially what source of locale information a particular version/runtime of .NET you're using, but my hunch is that you're seeing the effects of relying on ambient default locale, instead of explicitly using an appropriate locale when formatting. – Paul Dempsey Aug 02 '23 at 17:38
  • @PaulDempsey Not sure I follow... I am specifying es-US explicitly and get something different in Blazor WebAssembly from what I get everywhere else I try. If I use en-US or es-ES or fr-FR or even fr-US, everywhere I try agrees on the format string. It's only with es-US that I see this apparent discrepancy. – Patrick87 Aug 02 '23 at 18:04

0 Answers0