I don't really get the idea, why saving the result of this calculation in a double doesn't give me the right result: double a = 9/5 ; shouldn't it be the same as : double a = 9/5.0 ; Still I get totally different results and I am wondering why.
saving a value in a double
You must be signed in to leave a comment
15 October 2019, 14:54
In the first case Java is treating it as Integer Division. So it discards the remainder. So 5 goes into 9 evenly one time resulting in 1.0 In the second case, because the 5.0 is a double, Java treats it as real division and it keeps the remainder. My current source on this. I am looking through Oracle's docs too.
22 October 2019, 09:25
Thanks, crystal clear now :)