function format(input) { var n = parseFloat(input).toFixed(4); var re = /(d{1,3})(?=(d{3})+(?:.))/g; return n.replace(re, "$1,"); }