I have an equation in my application that works this way:
user enter a number X
(double) to use it in this equation:
double m = X * 0.015;
double resultIWant = X - m;
Note that if m
has more than 3 digits after comma I take exactly 3 digits without rounding by using this function:
public static double threeDigitsAfterCommaWithoutRounding(double retenue) {
return Math.floor(retenue * 1000) / 1000;
}
but I'm getting wrong calculation result :
Example:
if X = 1359.532
this is what I get in console:
1359.532 * 0.015 = 20.392979999999998
m = 20.392 (After using the function above)
1359.532 - 20.392 = 1339.1399999999999 !!!!
So the result should be 1339.14
and not 1339.1399999999999
What am I missing ?