Thousands separator based on user's settings?

I would like to display file sizes with thousands separators, based on the current operating system settings OF THE USER. What actually seems to happen is displaying it according to the webserver’s settings.

Appart from just parsing each string myself, is there another way to get European separators, when the page is loaded from a computer and browser with European settings?

I think you may meed the languagecode for the locale:

1 Like

Browsers don’t inspect and forward system locale infos, they have internal settings about languages the user has set, few of them, in a order of preference.


It could be used for a first time visit setting an empty preference, because a lot of people don’t know how to set this in a browser, and you should provide a way (read/write from a DB or cookie from example) to people choose and keep their preferences in your application.

1 Like

I don’t think Web2 was designed with this in mind.
Third party controls (like the WebDatePicker) are designed to change the display based on Browser configuration (sometimes this is not what we want, for example showing everything in English but the DatePicker is in Spanish).
Maybe you can open a Feature request but in the mean time you will need to check the languagecode and show/parsing as needed (my guess). I’m sure someone will comment if I’m wrong.

1 Like

@Ricardo_Cruz said something like this in the past:

Check the WebSession.LanguageCode In the WebSession.Opening event 
and change it to what you want as Me.LanguageCode = "en-GB"

What I don’t know is what’s the proper way to change it on the fly.

1 Like

Thanks! This will probably do it for my use case, as users are all Switzerland based.

Otherwise I guess I have to solve this on the client side, using JavaScript.

ChatGPT gave me this hint:

One can achieve this by using the Intl.NumberFormat object in JavaScript, which allows for number formatting according to the user’s locale. This API automatically handles the use of the correct thousands separator and decimal point based on the user’s international settings.

Here’s an example of how to use Intl.NumberFormat to format a number with the appropriate thousands separator according to the user’s locale:

function formatNumber(number) {
  // Retrieve the user's locale from the browser
  const userLocale = navigator.language;

  // Use the Intl.NumberFormat API with the detected locale
  const formatter = new Intl.NumberFormat(userLocale);

  // Format the number
  return formatter.format(number);

// Example usage
const numberToFormat = 1234567.89;
console.log(formatNumber(numberToFormat)); // This will output the number formatted according to the user's locale settings

ChatGPT is wrong again. :smile:


It’s the same thing as Xojo WebSession.LanguageCode

That once you change, all localized formats will follow.

If you want to force, for example, “de-ch”, you could try Me.LanguageCode = "de-CH" at the websession Opening() event.

Hmm, not automagicly…

You need to take some manual actions (creating a proper Locale object and use it) as

Var locale As New Locale(Session.LanguageCode)
Me.Text = DateTime.Now.ToString(locale, DateTime.FormatStyles.Long, DateTime.FormatStyles.None)

In your case, forcing a presentation, you could go more direcly and

Var deCH As New Locale("de-CH")
Label1.Text = DateTime.Now.ToString(deCH , DateTime.FormatStyles.Long, DateTime.FormatStyles.None)

Var v As Double = 123456789.0123
Label2.Text = v.ToString(deCH , "#,##0.00##")

I think that from here you are good to go. :wink:

1 Like

Great, thanks a lot for taking your time! I’ll give it a try tomorrow. Right now the carnival folks outside are bringing our house down - what a noise…

I’m also interested in this subject. :wink: