zyzzyzus

Short numbers in IGM

Jun 15th, 2014
25,687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. nums = ['k','M','B','T','Qa','Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', 'UnD', 'DuD', 'TrD', 'QaD', 'QiD', 'SeD', 'SpD', 'OcD', 'NoD', 'Vi', 'UnV'];
  2.  
  3.  
  4. function Beautify(num,floats)
  5. {
  6. if (!isFinite(num)) return 'Infinity'
  7. if(num < 1e3 || num >= parseFloat('1e' + 3*(nums.length))) return Math.round(num)
  8. var i = 0;
  9. while(num >= 1000)
  10. {
  11. num/=1000;
  12. i++;
  13. }
  14. num = Math.round(num*1000)/1000;
  15. if(num>=1000)
  16. {
  17. num/=1000;
  18. i++;
  19. num = Math.round(num*1000)/1000;
  20. } //deals with rounding errors
  21. num = num.toFixed(3);
  22. return num + nums[i - 1]
  23. }
Advertisement
Add Comment
Please, Sign In to add comment