mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 22:30:44 -05:00
fix: only round by 3 when float
This commit is contained in:
parent
42e9f92143
commit
9698732f03
1 changed files with 11 additions and 2 deletions
|
@ -89,7 +89,7 @@ function handleOperation() {
|
||||||
ops.clear();
|
ops.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result = result.toPrecision(3);
|
result = roundThreeDecimals(result);
|
||||||
updateDisplay(result);
|
updateDisplay(result);
|
||||||
ops.firstNum = result;
|
ops.firstNum = result;
|
||||||
ops.secondNum = String();
|
ops.secondNum = String();
|
||||||
|
@ -106,6 +106,15 @@ function updateDisplay(displayValue) {
|
||||||
display.textContent = 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) {
|
function handleOperatorClick(operatorClicked) {
|
||||||
|
|
||||||
// TODO handle ops for = or clear
|
// TODO handle ops for = or clear
|
||||||
|
|
Loading…
Reference in a new issue