diff --git a/calculator/calculator.app.js b/calculator/calculator.app.js index c520e80..afaa8a4 100644 --- a/calculator/calculator.app.js +++ b/calculator/calculator.app.js @@ -252,9 +252,9 @@ function displayOutput(num) { } } var numStr = num.toString(); - var displayStr = addSeparators(numStr); + var displayStr; - if (typeof num === 'number' && (g.stringWidth(displayStr) > g.getWidth() - 20 || (num !== 0 && Math.abs(num) < 1e-4))) { + if (typeof num === 'number' && (g.stringWidth(numStr) > g.getWidth() - 20 || (num !== 0 && Math.abs(num) < 1e-4))) { // try to format as scientific notation let precision = 10; // start with high precision while (precision >= 0) { @@ -268,6 +268,11 @@ function displayOutput(num) { if (precision < 0) { // if it still doesn't fit displayStr = toExponential(num, 0).replace("e", "E"); } + } else { + displayStr = addSeparators(numStr); + if (g.stringWidth(displayStr) > g.getWidth() - 20) { + displayStr = numStr; + } } num = displayStr;