Limit number of characters on display
This commit is contained in:
parent
4f92f52620
commit
e9597fa584
1 changed files with 17 additions and 2 deletions
19
script.js
19
script.js
|
|
@ -69,7 +69,7 @@ function displayOperator() {
|
||||||
function displayNum() {
|
function displayNum() {
|
||||||
if (mainScreen.textContent == "0" || isEval) {
|
if (mainScreen.textContent == "0" || isEval) {
|
||||||
mainScreen.textContent = this.textContent;
|
mainScreen.textContent = this.textContent;
|
||||||
} else {
|
} else if (mainScreen.textContent.length < 8) {
|
||||||
mainScreen.textContent += this.textContent;
|
mainScreen.textContent += this.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,11 +181,26 @@ function Calculator(str) {
|
||||||
if (!this.methods[op]) {
|
if (!this.methods[op]) {
|
||||||
return "Operation not supported."
|
return "Operation not supported."
|
||||||
}
|
}
|
||||||
return this.methods[op](a, b);
|
|
||||||
|
let result = this.methods[op](a, b);
|
||||||
|
return formatResult(result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatResult(result) {
|
||||||
|
const resultStr = result.toString();
|
||||||
|
const maxLength = 9;
|
||||||
|
|
||||||
|
if (resultStr.length > maxLength) {
|
||||||
|
expoResult = parseFloat(result).toExponential(maxLength - 6);
|
||||||
|
return expoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleKeys(e) {
|
function handleKeys(e) {
|
||||||
const operators = {
|
const operators = {
|
||||||
"+": "plus",
|
"+": "plus",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue