Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nums = ['thousand','million','billion','trillion','quadrillion','quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion'];
- function Beautify(num,floats)
- {
- if (!isFinite(num)) return 'Infinity'
- if(num < 1e3 || num >= parseFloat('1e' + 3*(nums.length))) return Math.round(num)
- var i = 0;
- while(num >= 1000)
- {
- num/=1000;
- i++;
- }
- num = Math.round(num*1000)/1000;
- if(num>=1000)
- {
- num/=1000;
- i++;
- num = Math.round(num*1000)/1000;
- } //deals with rounding errors
- num = num.toString();
- if(num.indexOf('.') == -1) num += '.000'
- else
- {
- dec = num.indexOf('.');
- while(num.slice(dec,num.length).length < 4) num += '0' //adds trailing 0s (if needed) to stop the numbers jumping around.
- }
- return num +" "+ nums[i - 1]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement