Unlike the real world, computers process mathematical operations in a slightly different way, although there is no significant difference after we understand why this is so.
1.) Why does he act like that?
Note that integers are integers, and integer variables can only store integers and cannot store or recognize decimal numbers. when you say 5/100, both 5 and 100 are integer literals for computers and are called integer division . The result should be 0.05, but since it is an integer division, the result will also be an integer , and since I said that integers cannot store decimal point values, the end part is after "." (decimal point) is completely ignored and therefore the result is 0 .
Adding more to this, although you are converting the result to double, it does not matter, because before it is actually converted to double, the result is already 0, and the integer 0 is converted to double, which ultimately leads to 0, 0 .
2.) How to get the desired result?
Other answers explain this solution very well, so I kindly ask you to refer to these answers, and not reinvent the wheel for you.
Hope this helps.
this. __curious_geek
source share