Simple Javascript Currency Format Like number_format in PHP

This javascript function is for change string to currency format, like number_format in PHP,
this function is built from regex, so simple code.


function number_format(number, delimiter){
return number.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1" + delimiter)
}


so you can use function above using this code

number_format("100000",".") // result will 100.000
number_format("1000000",",") // result will 1000,000


thank you, hope it useful

Comments