When doing the following in Java, i get as the result 0.0. Even though the result should be 10. This is an example calculation, in my code it's doing this with with double values.
double result = (10 / 100) * 100;
When doing the following in Java, i get as the result 0.0. Even though the result should be 10. This is an example calculation, in my code it's doing this with with double values.
double result = (10 / 100) * 100;
10
and 100
are integer literals, so 10 / 100
is evaluated in integer arithmetic which means that any remainder is discarded.
So you get (10 / 100) * 100 = (0) * 100
One fix is to promote one of the arguments to a double:
(10.0 / 100) * 100