utils.js 493 B

12345678910111213141516171819202122
  1. /*
  2. Utils.js
  3. This script holds utilities function that is commonly use
  4. across components
  5. */
  6. function abbreviateNumber(value) {
  7. var newValue = value;
  8. var suffixes = ["", "k", "m", "b", "t"];
  9. var suffixNum = 0;
  10. while (newValue >= 1000 && suffixNum < suffixes.length - 1) {
  11. newValue /= 1000;
  12. suffixNum++;
  13. }
  14. if (value > 1000){
  15. newValue = newValue.toFixed(2);
  16. }
  17. return newValue + suffixes[suffixNum];
  18. }