Matching date and number formats between JavaScript frontend and C# backend

I’m building an app that displays user information on the frontend and lets people download data through the backend in different file types. I’m using globalize.js on the frontend and .NET’s built-in globalization features on the backend.

The problem is that some languages show different formatting between the two sides. For example, dates might appear as “31.1.2016” in one place but “31-01-2016” in another. Numbers have the same issue - sometimes I get “1.234,56” and other times “1 234,56”.

I can’t just convert everything to strings before sending to the frontend because my chart components need actual numbers and date objects to work correctly.

Has anyone found a good way to make sure dates and numbers look the same on both the frontend and backend?

interesting challenge! you could try a shared locale config file that both js and c# can reference - store your format patterns centrally. quick question though: are you using identical culture codes on both sides? sometimes slight differences there cause issues.

Same headache here last year. I just standardized everything on ISO formats for data transfer (yyyy-mm-dd, decimal dots) and let each side handle its own display formatting. Way simpler than trying to sync formatters perfectly.

I faced a similar issue while developing a multi-tenant application tailored for various European locales. The solution that worked effectively involved creating a custom formatting layer on the backend to align with the patterns specified by globalize.js. It’s essential not to depend on .NET’s default culture formatting. Instead, I developed extension methods that utilize the same CLDR data as globalize.js. This approach allows you to maintain the integrity of your data types while ensuring consistent formatting. By parsing globalize.js locale files at startup, I was able to create corresponding C# formatters. For date formatting, I reconstructed patterns using C#'s custom format strings, and for numbers, I directly mapped the grouping and decimal symbols. This ensures that your charts receive accurate data types, while formatted values for display or export are consistent across both platforms.