I know, there are dozens of topic like this in site but I am having trouble with 3 problems and I couldnt figure out all of them at the same time.
Actually, I am trying to make a calculator for Android but sometimes I cannot get what I am expected to.
A part of my code is;
}else if(operator.equals("/")){
if(resultScreen.indexOf("/")==0){
strNum2 = resultScreen.substring(resultScreen.indexOf("/")+1,resultScreen.length());
intNum1 = result;
}else{
strNum1 = resultScreen.substring(0,resultScreen.indexOf("/"));
strNum2 = resultScreen.substring(resultScreen.indexOf("/")+1,resultScreen.length());
intNum1 = new BigDecimal(strNum1);
}
intNum2 = new BigDecimal(strNum2);
if(intNum2.equals(0)){
tvScreen.setText("Err");
resultScreen ="";
}else{
result = intNum1.divide(intNum2);
resultScreen = result.toString();
tvScreen.setText(resultScreen);
resultScreen ="";
}
}
When I try to;
22/7
It comes up;
3
How can I fix that?
By the way, I want to keep the exact value of decimal.