en-de output format
Description
Apologies in advance if this is in the wrong place, I'm coming up against a brick wall where to find out why this is happening. I've got a function app which simply returns the following string value
value.ToString("c", new CultureInfo("en-de"));
Locally this outputs "€12.99". Notice the euro at the front and decimal point. If I publish this code to Azure then it outputs "12,99 €"
Having spoken to Azure technical support they believe it's a code issue. What decides this output? Any help appreciated.
Configuration
Local .NET 6 Function Runtime 4.0 Locally Windows 11 / Windows 10 both work on x64 hardware.
Azure Published via VS2022. .NET 6 Function Runtime 4 North Europe
What decides this output? Any help appreciated.
Formatting is decided by localization resources present on the host OS. These resources are updated multiple times a year on every platform as part of the normal update process. Unless you explicitly put in a lot of work and manually manage these resources (and normally you shouldn't), you have no guarantee that any two running processes (including on the same host) will format data the same way. There's also no guarantees as to what the updates will or will not change - for instance, note the decimal separator has changed as well (, vs .). See this note.
As of .NET 5, Windows now uses the ICU libraries that Linux/the rest of the world uses. However, it still updates at a slower pace as some Linux distros.
Having spoken to Azure technical support they believe it's a code issue.
They're right, but the bug isn't necessarily in your formatting code directly. It's in your expectation/use of the result of the formatting.
- If you're using this data for interchange (eg via JSON on a REST endpoing), you should be using the
InvariantCulture. - If it's a localized piece of data on some localized document (eg, generated invoice), potentially ignore the formatted result altogether (for instances, in tests, only verify that you get something back, not the contents).
- If there are specific regulatory requirements, don't rely on the built-in culture data (which has different requirements), and instead use explicit formatting strings (or use your own explicitly created culture data).
That said...
value.ToString("c", new CultureInfo("en-de"));
is otherwise problematic -
- The language code of the culture id should be capitalized:
"en-DE"(although the parameter isn't actually case-sensitive). - This will always create a new
CultureInfoobject. On Windows, it will pick up any formatting customizations a user has set (which might be handy for UI applications, but wouldn't be appropriate for a server). Otherwise you should probably be usingGetCultureInfo.
Configuration
You can develop services on a different OS, but it can cause issues as you see here. Normally I'd suggest you use devcontainers, but I don't know that VS proper supports it for these project types. VSCode is an option, and VS2022 does support docker workloads, which may allow you to perform similar functionality, but I haven't tried it there.
Thanks a lot for your response and advice. Seems I may have naively thought that my local Windows should be the same Azure Windows hosts in regards to culture formats.
I may be thinking about this too simplistically but in my head the format is either defined correctly in the default host OS configuration or not. en-DE number formats I believe should be with a . not a , for the decimal separator. If I as a user then overwrite this then I could understand my .NET outputting based on their custom format but I don't believe this to be the case in my example.
but in my head the format is either defined correctly in the default host OS configuration or not
It might have been, at the point the OS was updated. That said, sometimes there are multiple potential answers. Note too that some updates are around things like whitespace used (there are different kinds of spaces), which don't always look different but can cause tests to fail.
Seems I may have naively thought that my local Windows should be the same Azure Windows hosts in regards to culture formats.
Nope! The Windows host in Azure will be a server OS, and you're running on a desktop OS. The function hosts also have their own update cadence.
Also, you should really look at using Linux as a host for your function apps, especially if you start using devcontainers. For one thing, that allows you to develop against the same "host" OS as the functions actually run on.
Tagging subscribers to this area: @dotnet/area-system-globalization See info in area-owners.md if you want to be subscribed.
Issue Details
Description
Apologies in advance if this is in the wrong place, I'm coming up against a brick wall where to find out why this is happening. I've got a function app which simply returns the following string value
value.ToString("c", new CultureInfo("en-de"));
Locally this outputs "€12.99". Notice the euro at the front and decimal point. If I publish this code to Azure then it outputs "12,99 €"
Having spoken to Azure technical support they believe it's a code issue. What decides this output? Any help appreciated.
Configuration
Local .NET 6 Function Runtime 4.0 Locally Windows 11 / Windows 10 both work on x64 hardware.
Azure Published via VS2022. .NET 6 Function Runtime 4 North Europe
| Author: | ditpfletcher |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
Closing the issue as @Clockwork-Muse already replied. @ditpfletcher feel free to send more questions if you still have any. Thanks!