I'm trying to simulate the ATM amount input in Java, ie. say the user keeps inputting "1", the amount shown should be:
0.00
0.01
0.11
1.11
11.11
111.11
I tried both Double and BigDecimal for processing:
println( ((new BigDecimal(current)).multiply(new BigDecimal(10)).add(new BigDecimal(0.01))).setScale(2, RoundingMode.HALF_UP).toString()) )
println( "" + Double.parseString(current) * 10 + 0.01 )
However both seems to show this instead:
0.00
0.01
0.11
1.11
11.1 <<< missing the 0.01 at the end
111.01
are they both due to a precision rounding error (I thought BigDecimal does not have this problem) or am I doing something wrong?