javascript - Output numbers with comma after 3 digits -
i have used jquery code
jquery.fn.digits = function(){ return this.each(function(){ jquery(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); }) } for number 150000 , want out put 150,000
but outputting : 150,000.00
i don't want these .00
i find for loop easier understand regex.
function addcommas(num) { var characters = parseint(num, 10).tostring(); var output = ''; (var offset = characters.length; offset > 0; offset -= 3) { output = characters.slice(math.max(offset - 3, 0), offset) + (output ? ',' + output : ''); } return output; }
Comments
Post a Comment