Is it possible to implement the toFixed()
method only when the input strings exceed 12 characters in length? If not, I would like the input to display normally, resembling a standard calculator app. I have experimented with a maximum character method, but the results are unsatisfactory and should not be relied upon.
https://i.sstatic.net/8yw1t.png
$(document).ready(function(){
var inputs=[""];
var totalString;
var operators1=["+", "-", "/", "*"];
//operators array including "." for validation
var operators2=["."];
var nums = [0,1,2,3,4,5,6,7,8,9];
function getValue(input){
if(operators2.includes(inputs[inputs.length-1])===true && input==="."){
console.log("Duplicate '.'");
}
else if(inputs.length===1 && operators1.includes(input)===false)
{
inputs.push(input);
}
else if(operators1.includes(inputs[inputs.length-1])===false){
inputs.push(input);
}
else if(nums.includes(Number(input))){
inputs.push(input);
}
update();
}
function update(){
totalString = inputs.join("");
$("#steps").html(totalString);
console.log(inputs);
}
function getTotal(){
totalString = inputs.join("");
$("#steps").html(eval(totalString));
}
$("a").on("click", function(){
if(this.id==="deleteAll"){
inputs=[""];
update();
}
else if(this.id==="backOne"){
inputs.pop();
update();
}
else if(this.id==="total"){
getTotal();
}
else{
if(inputs[inputs.length-1].indexOf("+","-","/","*")===-1)
{
getValue(this.id);
}
else
{
getValue(this.id);
}
}
});
});