I have block displaying the number of following for a twitter handle. Works great. The only issue, is that there are 11,000+ followers, and the API doesn't throw in the comma. How would I incorporate JavaScript to format the number so it looks nice?
Here's the twitter code I'm using:
$(function(){
$.ajax({
url: 'http://api.twitter.com/1/users/show.json',
data: {screen_name: 'handle'},
dataType: 'jsonp',
success: function(data) {
$('#followers').html(data.followers_count);
}
});
});
Thanks to neiker for help with a solution!
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
$.ajax({
url: 'http://api.twitter.com/1/users/show.json',
data: {screen_name: 'handle'},
dataType: 'jsonp',
success: function(data) {
$('#followers').html(numberWithCommas(data.followers_count));
}
});