I am using the following Javascript to display my Instagram counter on my site.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(function() { $.ajax({ type: "GET", dataType: "jsonp", cache: true, url: "https://api.instagram.com/v1/users/{ID}/?access_token={ACCES_TOKEN}", success: function(data) { var ig_count = data.data.counts.followed_by.toString(); ig_count = add_commas(ig_count); $(".instagram_count").html(ig_count); } }); function add_commas(number) { if (number.length > 3) { var mod = number.length % 3; var output = (mod > 0 ? (number.substring(0, mod)) : ''); for (i = 0; i < Math.floor(number.length / 3); i++) { if ((mod == 0) && (i == 0)) { output += number.substring(mod + 3 * i, mod + 3 * i + 3); } else { output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3); } } return (output); } else { return number; } } }); </script> <span class="instagram_count"> </span>
As you can see, there is a function to add a comma where necessary. I would also like to display a reduced number of followers, e.g. 3.291 , like 3.2k , in another class. Thus, maintaining the total number of followers in one class and reducing it in another. I'm not the best at JavaScript, but I was learning slowly.
I found a similar question ( Is there a way to round numbers in a reader-friendly format (for example, $ 1.1 thousand) ), but they could not implement it in my JavaScript.
Any help is greatly appreciated.
javascript instagram
Jack McLaughlin Sep 01 '14 at 19:27 2014-09-01 19:27
source share