Possible Duplicate:
how to print number with commas as thousands separators in Javascript
I have a function that will add thousand seperators to a number, however it is not working well when a decimal is passed in:
function thousandSep(val) {
return String(val).split("").reverse().join("")
.replace(/(.{3}\B)/g, "$1,")
.split("").reverse().join("");
}
If I pass in 10000, I get 10,000 as expected.
However, passing in 10,000.00 I get 1,000,0.00.
How can I modify the function to handle decimals?