javascript - add commas to a number in jQuery -
i have these numbers
10999
, 8094
, 456
and want add comma in right place if needs looks this
10,999
, 8,094
, 456
these within p tag <p class="points">10999</p>
etc.
can done?
i've attempted here of other posts http://jsfiddle.net/pdwtu/1/ can't seem work
thanks
jamie
update
messed around bit , managed figure out here http://jsfiddle.net/w5jwy/1/
going @ new globalization plugin better way of doing it
thanks
jamie
works on browsers, need.
function commaseparatenumber(val){ while (/(\d+)(\d{3})/.test(val.tostring())){ val = val.tostring().replace(/(\d+)(\d{3})/, '$1'+','+'$2'); } return val; }
wrote compact, , point, regex. straight js, can use in jquery so:
$('#elementid').html(commaseparatenumber(1234567890));
or
$('#inputid').val(commaseparatenumber(1234567890));
Comments
Post a Comment