I am attempting to create a calculator app, when I add three doubles together ex. (1.1 + 1.1 + 1.1) 3.3000000000000003 is returned. This only occurs when three numbers are added together (1.1 + 1.1) returns 2.2
Is their a way to use decimal format to round only if 2 digits in a row are zero to prevent this from happening?
Thank you!
Please let me know if you need to see more of my code, I think this is sufficient though I may be wrong.
equals button method
equals_button_IB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//new value being added everytime addition button is pressed, last number to be added will not have addition button
//pressed after it, so this adds the last value to the values array list
values.add(current_screen_value);
System.out.println(values);
double sum = 0;
for(int i = 0; i<values.size(); i++){
sum+= Double.parseDouble(values.get(i));
}
System.out.println(sum);
clearScreen(null);
updateScreen(String.valueOf(sum));
}
});