How can I modify the function below to make it stop adding commas once we hit the decimal marker?
addCommas = function(number) {
if(number === undefined) {
return '';
}
while(/(\d+)(\d{3})/.test(number.toString())) {
number = number.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return number;
}
addCommas(0.123456); // Outputs 0.123,456, should output 0.123456