Gavin Newsom - Wordpress Theme - Debt Consolidation - Air Jordan Release Date - Debt Consolidation

PDA

View Full Version : browser locale, comma as decimal point and toLocaleString


claude_v
Feb 16th 2007, 6:43 am
Hi!

I have a bunch of numbers I show in the browser's locale using Number.toLocaleString(). In France for example the ',' is going to be used as a separator.

My issue is that those fields are input/output and I need to convert the user data back to number, and Number(string) will not recognize the ',' -> NAN.

I do not see any symmetrical operation to toLocaleString() that would let me do that (something like NumberFormat.parseLocaleString(string). Before I do my own regexp, I just want to make sure I'm not missing something.

Thanks!

Claude

ajsa52
Feb 16th 2007, 10:26 am
You can try replacing ',' with '.'
Number( string.replace(',', '.') );
If there is '.' instead of ',' nothing is replaced.

claude_v
Feb 16th 2007, 1:11 pm
Thanks! That's a good idea as long as . is not used as the thousand separator.
Claude