javascript - Number.toLocaleString() with custom separators -


i need format number in javascript separators may defined @ runtime.

the combination of thousand , decimal separator may not match specific locale.

is there way provide thousand , decimal separator in javascript tolocalestring()? or use numberformat explicitly values define?

i see examples using locale codes, , using other values ( https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/number/tolocalestring ) these don't cover use case.

one option format string known separators, , find/replace unknown separators.

function formatnum(num, separator, fraction) {   var str = num.tolocalestring('en-us');   str = str.replace(/\./, fraction);   str = str.replace(/,/g, separator);   return str; }  formatnum(12342.2, "a", "x"); //12a342x2 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -