Skip to content

Instantly share code, notes, and snippets.

@SaladFork
Last active July 24, 2018 21:11
Show Gist options
  • Save SaladFork/794946ad642170d15656f9fe2bfa197b to your computer and use it in GitHub Desktop.
Save SaladFork/794946ad642170d15656f9fe2bfa197b to your computer and use it in GitHub Desktop.
Create numbers that are a bit more human-friendly to read
// Example usage:
// Number(5).hundred() // => 500
// Number(3).billion() // => 3000000000
[
['hundred', 1e2],
['thousand', 1e3],
['million', 1e6],
['billion', 1e9],
['trillion', 1e12],
['quadrillion', 1e15],
['quintillion', 1e18],
['sextillion', 1e21],
['septillion', 1e24],
['octillion', 1e27],
['nonillion', 1e30],
['decillion', 1e33],
['undecillion', 1e36],
['duodecillion', 1e39],
['tredecillion', 1e42],
].forEach(([name, multiplier]) => {
Number.prototype[name] = function() { return this * multiplier; }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment