fixed Calculatrice app

preferencesAboutTextFull
unknown 12 years ago
parent 77af92e25d
commit 55374a24da
  1. 33
      resources/library/applications/Calculatrice.wgt/js/ubw-main.js

@ -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,10 +389,10 @@ 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;
break; break;
case "-": case "-":
@ -516,10 +514,27 @@ function init(){
displayTrunk = displayTrunk.substr(0, displayTrunk.length-1); displayTrunk = displayTrunk.substr(0, displayTrunk.length-1);
}; };
calc += String(char); if(calc == "0"){
displayTrunk += String(char); if(char != "0"){
historyTrunk += String(char); if(char != "."){
lastchar.type = "Number"; 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);
displayTrunk += String(char);
historyTrunk += String(char);
lastchar.type = "Number";
}
} }
// char is an operator // char is an operator
else { else {

Loading…
Cancel
Save