#Java
1 messages · Page 1 of 1 (latest)
I use calculator to calculate and get the answer is 95 but why after run the system give me the answer is 67 ? Help 🙏
as I already said your problem is 9 / 5
its using integer division
which will evaluate to 1
if you instead do 9.0 / 5.0 you will get 1.8
But 1.8 mathematical carry not became 2 ?
if you want to round, you need to manually do it
there's Math.ceil if you want to round up
Integer division does not round, it just "cuts" out the decimal part
Some examples:
- 21/2 would be 10.5, but integer division makes it 10
- 10/3 would be 3.333... but integer division makes it 3
- 1/4 would be 0.25 but integer division makes it 0
You see?
That's bad examples because they show rounding down 
Also rounding down = truncating, they both give the same result
And... no, integer division doesn't round down and doesn't truncate either, it rounds toward 0, so -2/3 == 0, not -1
I think most people refer to truncating as -1.5 -> -1