i have issue number inputting. user enters large number many zeros, , missing 1 or 2 0 difficult accurately count them.
i think javascript can work out showing user number have inducted, formatted commas.
eg:
input: | 1230000000000 |
result: 1,230,000,000,000
how accomplished?
use following function in javascript
function addcommas(nstr) { nstr += ''; x = nstr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }
example
addcommas('9999999.00') // 9,999,999.00
Comments
Post a Comment