浏览代码

Add small number word mode - only goes up to septillion

tags/v0.0.7
Fen Dweller 5 年前
父节点
当前提交
599e085c1c
找不到此签名对应的密钥 GPG 密钥 ID: E80B35A6F11C3656
共有 2 个文件被更改,包括 25 次插入0 次删除
  1. +5
    -0
      gorge.js
  2. +20
    -0
      numbers.js

+ 5
- 0
gorge.js 查看文件

@@ -29,6 +29,11 @@ const numberModes = {
words: { words: {
name: "Words", name: "Words",
render: numberText, render: numberText,
next: "smallWords"
},
smallWords: {
name: "Small Words",
render: numberTextSmall,
next: "scientific" next: "scientific"
}, },
scientific: { scientific: {


+ 20
- 0
numbers.js 查看文件

@@ -2,6 +2,26 @@ function render(val, places = 1, smallPlaces = 0) {
return numberMode.render(val, places, smallPlaces); return numberMode.render(val, places, smallPlaces);
} }


function numberTextSmall(val, places = 1, smallPlaces = 0) {
if (isNaN(val)) {
throw new RangeError("Invalid number: " + val);
}
if (val < 1000) {
return round(val, smallPlaces);
}

let power = Math.floor(Math.log10(val));

let order = Math.floor(power / 3);

adjusted = round(val / Math.pow(1000, order), places).toFixed(places);

if (order <= 8)
return adjusted + " " + _numberWords[order - 1];
else
return numberTextSmall(val / Math.pow(10, 24), places, smallPlaces) + " septillion"
}

function numberText(val, places = 1, smallPlaces = 0) { function numberText(val, places = 1, smallPlaces = 0) {
if (isNaN(val)) { if (isNaN(val)) {
throw new RangeError("Invalid number: " + val); throw new RangeError("Invalid number: " + val);


正在加载...
取消
保存