Created
February 21, 2014 18:29
-
-
Save cjthompson/9140248 to your computer and use it in GitHub Desktop.
Convert a number into a human readable number with 3 significant digits followed by 'K' (thousand), 'M' (million), or 'B' (billion)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readableNumber(num) { | |
var s = ['', 'K', 'M', 'B']; | |
var e = Math.floor(Math.log(num) / Math.log(1000)); | |
return (num / Math.pow(1000, e)).toPrecision(3) + s[e]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment