fix: only round by 3 when float

This commit is contained in:
Mike 2023-10-12 22:11:49 -04:00
parent 42e9f92143
commit 9698732f03

View file

@ -89,7 +89,7 @@ function handleOperation() {
ops.clear();
return;
}
result = result.toPrecision(3);
result = roundThreeDecimals(result);
updateDisplay(result);
ops.firstNum = result;
ops.secondNum = String();
@ -106,6 +106,15 @@ function updateDisplay(displayValue) {
display.textContent = displayValue;
}
function roundThreeDecimals(number) {
if (!Number.isInteger(number) && Number.isFinite(number)
) {
return parseFloat(number.toPrecision(3));
} else {
return number;
}
}
function handleOperatorClick(operatorClicked) {
// TODO handle ops for = or clear