Skip to content

Commit 73ff692

Browse files
committed
Refactor formatDisplay for better readability
1 parent 67c4c64 commit 73ff692

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ document.addEventListener('DOMContentLoaded', function() {
1616
displayValue = "";
1717
}
1818
displayValue += value;
19-
if (displayValue.length > MAX_DISPLAY_LENGTH) {
20-
displayValue = parseFloat(displayValue).toExponential(MAX_DISPLAY_LENGTH - 7);
21-
}
19+
displayValue = formatDisplay(displayValue);
2220
displayOutput.textContent = displayValue;
2321
}
2422

23+
function formatDisplay(value) {
24+
if (value.length > MAX_DISPLAY_LENGTH) {
25+
return parseFloat(displayValue).toExponential(MAX_DISPLAY_LENGTH - 7);
26+
}
27+
return value;
28+
}
29+
2530
function resetDisplay() {
2631
displayValue = "";
2732
calculationJustCompleted = false;

0 commit comments

Comments
 (0)