Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery - Add comma to numbers

0 votes
7 views
added Jun 1 in jQuery by LC Marshal Lieutenant (12,590 points)
edited Jun 19 by LC Marshal
//placed plugin globally, so it can be used globally 
$.fn.digits = function(){ 
    return this.each(function(){ 
        $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
    })
}

//to add comma on JSON object 
var areaname = $('h1.page-header').text(),
    lookforstate = $('ol.breadcrumb li:last-child').text(),
    trimstate = lookforstate.split(","),
    resultstate  = trimstate [trimstate.length-1],
    getstate = $.trim(resultstate),
    outlookLislnk = 'https://alice.propedge.my/property/v1/nsearch?&state=',
    incDistrcRent = '&listing_type=rental&district=',
    fulloutLisRent = outlookLislnk + getstate + incDistrcRent + areaname;

$('input#count-rent').fadeIn(300).val(fulloutLisRent.found).digits();
$('.count-rent').fadeIn(300);
});

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...