瀏覽代碼

Show floats with two decimals instead of calling toString()

tags/v1.1.0
Fen Dweller 5 年之前
父節點
當前提交
b210cc4276
共有 1 個檔案被更改,包括 5 行新增5 行删除
  1. +5
    -5
      units.js

+ 5
- 5
units.js 查看文件

@@ -45,7 +45,7 @@ function number(value, type="full", precision=3) {
switch(type) { switch(type) {
case "full": case "full":
if (Math.log(value) / Math.log(10) < 10) { if (Math.log(value) / Math.log(10) < 10) {
return val.toString();
return val.toFixed(2);
} }


case "scientific": return val.toExponential(precision).toString(); case "scientific": return val.toExponential(precision).toString();
@@ -90,9 +90,9 @@ function number_words_repeated(value) {
return "a lot of"; return "a lot of";
var scale = Math.floor(Math.log(value) / Math.log(1000)); var scale = Math.floor(Math.log(value) / Math.log(1000));
if (scale < 0) if (scale < 0)
return value.toString();
return value.toFixed(2);
switch(scale) { switch(scale) {
case 0: return value.toString();
case 0: return value.toFixed(2);
case 1: return Math.round(value / 1e3).toString() + " thousand"; case 1: return Math.round(value / 1e3).toString() + " thousand";
case 2: return Math.round(value / 1e6).toString() + " million"; case 2: return Math.round(value / 1e6).toString() + " million";
case 3: return Math.round(value / 1e9).toString() + " billion"; case 3: return Math.round(value / 1e9).toString() + " billion";
@@ -111,9 +111,9 @@ function number_words_repeated(value) {
function number_prefix(value) { function number_prefix(value) {
var scale = Math.floor(Math.log(value) / Math.log(1000)); var scale = Math.floor(Math.log(value) / Math.log(1000));
if (scale < 0) if (scale < 0)
return value.toString();
return value.toFixed(2);
switch(scale) { switch(scale) {
case 0: return value.toString();
case 0: return value.toFixed(2);
case 1: return Math.round(value / 1e3).toString() + "K"; case 1: return Math.round(value / 1e3).toString() + "K";
case 2: return Math.round(value / 1e6).toString() + "M"; case 2: return Math.round(value / 1e6).toString() + "M";
case 3: return Math.round(value / 1e9).toString() + "G"; case 3: return Math.round(value / 1e9).toString() + "G";


Loading…
取消
儲存