|
|
@ -350,7 +350,6 @@ function init(){ |
|
|
|
|
|
|
|
|
|
|
|
function compute(){ |
|
|
|
function compute(){ |
|
|
|
var result; |
|
|
|
var result; |
|
|
|
//alert(calc)
|
|
|
|
|
|
|
|
if(calc.length <= 1) |
|
|
|
if(calc.length <= 1) |
|
|
|
result = eval(calc); |
|
|
|
result = eval(calc); |
|
|
|
else{ |
|
|
|
else{ |
|
|
@ -362,7 +361,6 @@ function init(){ |
|
|
|
operation = (calc.indexOf("+", 0) != -1)?calc.charAt(calc.indexOf("+", 0)):((calc.indexOf("*", 0) != -1)?calc.charAt(calc.indexOf("*", 0)):((calc.indexOf("/", 0) != -1)?calc.charAt(calc.indexOf("/", 0)):((calc.indexOf("-", 0) != -1)?calc.charAt(calc.indexOf("-", 0)):""))); |
|
|
|
operation = (calc.indexOf("+", 0) != -1)?calc.charAt(calc.indexOf("+", 0)):((calc.indexOf("*", 0) != -1)?calc.charAt(calc.indexOf("*", 0)):((calc.indexOf("/", 0) != -1)?calc.charAt(calc.indexOf("/", 0)):((calc.indexOf("-", 0) != -1)?calc.charAt(calc.indexOf("-", 0)):""))); |
|
|
|
fNumber = fMinus + calc.substring(0, calc.indexOf(operation, 0)); |
|
|
|
fNumber = fMinus + calc.substring(0, calc.indexOf(operation, 0)); |
|
|
|
lNumber = calc.substring(calc.indexOf(operation, 0)+1, calc.length); |
|
|
|
lNumber = calc.substring(calc.indexOf(operation, 0)+1, calc.length); |
|
|
|
//alert(fNumber + " | " + operation + " | " + lNumber)
|
|
|
|
|
|
|
|
result = calcIt(fNumber, operation, lNumber); |
|
|
|
result = calcIt(fNumber, operation, lNumber); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -391,8 +389,8 @@ function init(){ |
|
|
|
lCount = (lNumber.indexOf(".", 0) != -1)?lNumber.substring(lNumber.indexOf(".", 0)+1, lNumber.length):""; |
|
|
|
lCount = (lNumber.indexOf(".", 0) != -1)?lNumber.substring(lNumber.indexOf(".", 0)+1, lNumber.length):""; |
|
|
|
length = (fCount.length >= lCount.length)?fCount.length:lCount.length; |
|
|
|
length = (fCount.length >= lCount.length)?fCount.length:lCount.length; |
|
|
|
length = Math.pow(10, length); |
|
|
|
length = Math.pow(10, length); |
|
|
|
fNumber = fNumber * length; |
|
|
|
fNumber = Math.round(fNumber * length); |
|
|
|
lNumber = lNumber * length; |
|
|
|
lNumber = Math.round(lNumber * length); |
|
|
|
switch(operation){ |
|
|
|
switch(operation){ |
|
|
|
case "+": |
|
|
|
case "+": |
|
|
|
result = (fNumber + lNumber)/length; |
|
|
|
result = (fNumber + lNumber)/length; |
|
|
@ -516,11 +514,28 @@ function init(){ |
|
|
|
displayTrunk = displayTrunk.substr(0, displayTrunk.length-1); |
|
|
|
displayTrunk = displayTrunk.substr(0, displayTrunk.length-1); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(calc == "0"){ |
|
|
|
|
|
|
|
if(char != "0"){ |
|
|
|
|
|
|
|
if(char != "."){ |
|
|
|
|
|
|
|
calc = String(char); |
|
|
|
|
|
|
|
displayTrunk = String(char); |
|
|
|
|
|
|
|
historyTrunk = String(char); |
|
|
|
|
|
|
|
lastchar.type = "Number"; |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
calc += String(char); |
|
|
|
|
|
|
|
displayTrunk += String(char); |
|
|
|
|
|
|
|
historyTrunk += String(char); |
|
|
|
|
|
|
|
lastchar.type = "Number"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
char = (char == ".")?((displayTrunk.indexOf(".", 0) != -1)?"":"."):char; |
|
|
|
calc += String(char); |
|
|
|
calc += String(char); |
|
|
|
displayTrunk += String(char); |
|
|
|
displayTrunk += String(char); |
|
|
|
historyTrunk += String(char); |
|
|
|
historyTrunk += String(char); |
|
|
|
lastchar.type = "Number"; |
|
|
|
lastchar.type = "Number"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// char is an operator
|
|
|
|
// char is an operator
|
|
|
|
else { |
|
|
|
else { |
|
|
|
if(calc.length === 0){ |
|
|
|
if(calc.length === 0){ |
|
|
|