Reputation: 15616
Is there any jQuery plugin which convert numeric string into a standard format let say:
200000 to 2,00,000
1000 to 1,000
398740 to 3,987,40
and so on..
Upvotes: 1
Views: 732
Reputation: 144659
try this:
var s = 200000;
var converted = s.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
or:
$.fn.convert = function() {
return this.each(function(){
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
})
}
you can call it for converting texts of selected elements like other jQuery methods:
$('#elem').convert()
Upvotes: 1