[Javascript] thousand separator
Shawn Milo
milo at linuxmail.org
Thu Jun 3 15:22:53 CDT 2004
Well, I figured that there's no need to pass or
figure out the delimiter for the decimal point,
because we're never adding one, just observing
its position.
As for the comma versus period thou delimiter,
I just decided to default to the period, and
change it to a comma if the browser is reporting
'us-en' (case insensitive).
Thanks to Hakan, David, Paul, Hassan, and Flavio
for providing the pieces to this. I just put
your ideas together to create this.
Shawn
Okay, here's the gravy:
function addCommas_skm(someNum){
var strThou = '.';
var usTest = navigator.systemLanguage + '' + navigator.language;
if (usTest.match(/en-us/i)){ strThou = ',';}
while (someNum.match(/^\d\d{3}/)){
someNum = someNum.replace(/(\d)(\d{3}(\.|,|$))/, '$1' + strThou + '$2');
}
return someNum;
}
More information about the Javascript
mailing list