From 5cb5ee604b7ecf371cd14a99d3455f8734974a29 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 14 Mar 2026 15:17:25 -0600 Subject: [PATCH] fix: Ensure thousands separators display without premature scientific notation Co-authored-by: aider (gemini/gemini-2.5-pro) --- calculator/calculator.app.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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;