Advertisement
Guest User

hope this works

a guest
Jul 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Beautify(num,floats)
  2. {
  3. if (!isFinite(num)) return 'Infinity'
  4. if(num < 1e3) return Math.round(num)
  5. var i = 0;
  6. while(num >= 10)
  7. {
  8. num/=10;
  9. i++;
  10. }
  11. num = Math.round(num*100)/100;
  12. if(num>=10)
  13. {
  14. num/=10;
  15. i++;
  16. num = Math.round(num*100)/100;
  17. } //deals with rounding errors
  18. num = num.toFixed(2);
  19. return num + "e" + i
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement