From 3c602488f09c744c3150098999621e89e28eaf7a Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 8 Dec 2019 10:40:13 -0500 Subject: [PATCH] Fix missing quintillion, add numbers up to vigintillion, add compound numbers --- numbers.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/numbers.js b/numbers.js index a93d85a..59952f9 100644 --- a/numbers.js +++ b/numbers.js @@ -11,20 +11,34 @@ function numberText(val, places=1, smallPlaces = 0) { let order = Math.floor(power / 3); - val = round(val / Math.pow(1000, order), places).toFixed(places); + adjusted = round(val / Math.pow(1000, order), places).toFixed(places); - return val + " " + _numberWords[order]; + if (order <= 21) + return adjusted + " " + _numberWords[order - 1]; + else + return numberText(val / Math.pow(10, 63), places, smallPlaces) + " vigintillion" } _numberWords = { - 1: "thousand", - 2: "million", - 3: "billion", - 4: "trillion", - 5: "quadrillion", + 0: "thousand", + 1: "million", + 2: "billion", + 3: "trillion", + 4: "quadrillion", + 5: "quintillion", 6: "septillion", 7: "sextillion", 8: "octillion", 9: "nonillion", - 10: "decillion" + 10: "decillion", + 11: "undecillion", + 12: "duodecillion", + 13: "tredecillion", + 14: "quattuordecillion", + 15: "quindecillion", + 16: "sexdecillion", + 17: "septendecillion", + 18: "octodecillion", + 19: "novemdecillion", + 20: "vigintillion", }