Cool function to convert integer value into money value (Adds comma after 3 digits from right)

This function adds comma to make it look like money value.
function addComma(val)
{
var regEx = /(\d+)(\d{3})/;
while (regEx.test(val))
{
val = val.replace(regEx, ‘$1’ + ‘,’ + ‘$2’);
}
return val;
}

Leave a Reply

Your email address will not be published. Required fields are marked *