|
- function render(val, places=1, smallPlaces = 0) {
- return numberText(val, places, smallPlaces);
- }
-
- function numberText(val, places=1, smallPlaces = 0) {
- if (val < 1000) {
- return round(val, smallPlaces);
- }
-
- let power = Math.floor(Math.log10(val));
-
- let order = Math.floor(power / 3);
-
- val = round(val / Math.pow(1000, order), places).toFixed(places);
-
- return val + " " + _numberWords[order];
- }
-
- _numberWords = {
- 1: "thousand",
- 2: "million",
- 3: "billion",
- 4: "trillion",
- 5: "quadrillion",
- 6: "septillion",
- 7: "sextillion",
- 8: "octillion",
- 9: "nonillion",
- 10: "decillion"
- }
|