712 / 100
IS NOT 7.12
. It's 7
. If you'll divide 7
by 10
, then you'll get 0
. If you'll take modulus of 7 % 10
, you'll get 7
, because it's the rest of dividing 7/10
. Dividing ints always rounds down to the full decimal value, there is no rest. That's what the modulus operator is for and you need to evaluate them separately.
Example:
Your input is 12345
. 12345/100
gives you 123
, because you have 123 full hundrets
in the input. Then 123/10
would give you 12
, because there are 12 full tens
in 123
and 123%10
would give you 3
(which is the number you're looking for), because it's the rest from dividing 123/10
.
And if you'll ever need division in the school-math type, use floating point types, like float
or double
. F.e. 12345f/100
would give you approximately 123.45f
.