B4J Question [BANano] [SOLVED] Best approaches to handle computations based on Regional Settings

Mashiane

Expert
Licensed User
Longtime User
Hi there

In South Africa, the decimal separator is . and the thousands separator most is ,

In Rio, its the other way round. Seemingly NumberFormat uses the regional settings of the device, I could be wrong.

So whilst adding numbers with 10.10 + 20.20 in South Africa will work without hustles.

Adding 10,10 and 20,20 results in NaN.

What have been the best approaches to handle this?

Thanks in advance.

PS: I also picked something strange. Running the same app hosted overseas in my computer worked well without issues and someone having different regional settings opening the same app, it broke when these computations were done. So im wondering, why is it not using the server regional settings and using client webapp settings?
 
Solution
Browsers will always take the client side, never the server. And even funnier, each browser has its own way to handle it when asking for the val. Whatever the user inputs, you will have to make sure it is a valid JavaScript float (which will always be a dot, never a comma) yourself. On way could be that you catch it in the keydown/keyup event if the user enters a comma and change it to a dot. or before putting it in double, replace the comma by a dot of the text you got from the input. It's dirty, but it does the trick.

Alwaysbusy

alwaysbusy

Expert
Licensed User
Longtime User
Browsers will always take the client side, never the server. And even funnier, each browser has its own way to handle it when asking for the val. Whatever the user inputs, you will have to make sure it is a valid JavaScript float (which will always be a dot, never a comma) yourself. On way could be that you catch it in the keydown/keyup event if the user enters a comma and change it to a dot. or before putting it in double, replace the comma by a dot of the text you got from the input. It's dirty, but it does the trick.

Alwaysbusy
 
Upvote 2
Solution
Top