From fc7ba45b45c6c4e27477cae9d7f282f1d7a46aa9 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 1 Jun 2018 10:00:38 -0400 Subject: [PATCH] Full numbers still go to scientific once they get sufficiently large --- units.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/units.js b/units.js index ea7faf7..ba55251 100644 --- a/units.js +++ b/units.js @@ -43,7 +43,11 @@ function numberRough(value,suffix="") { function number(value, type="full", precision=3) { var val = parseFloat(value); switch(type) { - case "full": return val.toString(); + case "full": + if (Math.log(value) / Math.log(10) < 10) { + return val.toString(); + } + case "scientific": return val.toExponential(precision).toString(); case "words": return number_words_repeated(val); case "prefix": return number_prefix(val);