Skip to content

Instantly share code, notes, and snippets.

@cjthompson
Created February 21, 2014 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjthompson/9140248 to your computer and use it in GitHub Desktop.
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)
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