multiplying DecimalFormat number (no longer rounded properly)
I'm basically trying to use DecimalFormat to get to two decimal places. I'm taking two integer values then dividing them and casting to a double I've put in sample values below. When I do as below I get a value that is no longer to two decimal places. It seems to be when multiply by the 3 it loses it's rounding.
DecimalFormat df = new DecimalFormat("#.00"); double d = Double.parseDouble(df.format((double)5/6))*3; System.out.println(d);
Can you let me know why this occurs and how to fix this?
In the statemet:
double d = Double.parseDouble(df.format((double)5/6))*3;
the formatting is not preserved (Double returns a double).
You could do, e.g.: