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
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Nutty Coder
15 October 2019, 14:54useful
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.
+2
Paul
22 October 2019, 09:25
Thanks, crystal clear now :)
0