Hey guys i am building a java calculator and everything works fine except the fact that i am doing calculations with double numbers.
The problem is that when i want to do 0.3 + 0.5 = 0.8 works fine, but when i do 6 + 6 = 12.0
How can i fix this so when the result is .0 at the end it displays an integer?
My code is:
public void actionPerformed(ActionEvent e) {
int j = 0;
r2 = Double.parseDouble(textField.getText());
if (option.equals("+")) {
result = r1 + r2;
}
if (option.equals("-")) {
result = r1 - r2;
}
if (option.equals("*")) {
result = r1 * r2;
}
if (option.equals("/")) {
result = r1 / r2;
}
textField.setText(result + " ");
}