I have a button that, when I press it I want it to update a label (which starts at 0.0) to + 0.1
I get the following:
0.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.79999999999999999
0.89999999999999999
0.99999999999999999
1.09999999999999999
The code I have is:
double Number = Double.parseDouble(txtNumber.getText());
double Generator = 0.1;
Number = (Number + Generator);
txtNumber.setText(Number + "");
I understand that the way computers work with numbers are not exactly 0.3 but more like 0.2999999... I just wanted a way to round the number so I can easily add 0.1(to)0.9 together without a mass of decimal places.
I have tried adding
Math.round((Number + Generator) * 100) / 100;
although it rounds it downwards to 0 so the label doesn't update.