diff --git a/calculator/calculator.app.js b/calculator/calculator.app.js index c97bca5..77bf8e7 100644 --- a/calculator/calculator.app.js +++ b/calculator/calculator.app.js @@ -261,11 +261,19 @@ function displayOutput(num) { num = num.substr(1); } } - num = num.toString(); + var numStr = num.toString(); + if (typeof num === 'number' && (numStr.length > RESULT_MAX_LEN || (num !== 0 && Math.abs(num) < 1e-4))) { + let precision = RESULT_MAX_LEN - 8; + if (precision < 0) precision = 0; + num = num.toExponential(precision).replace("e", "E"); + } else { + num = numStr; + } num = num.replace("-","- "); // fix padding for '-' g.setFont('7x11Numeric7Seg', 2); if (num.length > RESULT_MAX_LEN) { - num = num.substr(0, RESULT_MAX_LEN - 1)+'...'; + if (num.indexOf("E") < 0) + num = num.substr(0, RESULT_MAX_LEN - 1)+'...'; } } g.setFontAlign(1,0);