I have a java class that multiplies one double with another. The result is sometimes imprecise, for example
7.2 * 21 gives 151.20000000002 when it should be 151.2
and
1.2 * 9 gives 10.799999999 when it should be 10.8.
Can anyone tell me why this is so and what datatype I should use to ensure precision in arithmetic?
7.2 * 21 gives 151.20000000002 when it should be 151.2
and
1.2 * 9 gives 10.799999999 when it should be 10.8.
Can anyone tell me why this is so and what datatype I should use to ensure precision in arithmetic?