• Post Reply Bookmark Topic Watch Topic
  • New Topic

java multiplication  RSS feed

 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just trying to do System.out.println(1024.235*100); & it prints 109123.49999999999 but if I do System.out.println(1023.235*100); then it prints 102323.5.
So can any one please explain why this is happening? I understand it is something with 1024 which is 2^10 but not sure why this is happening.

Thanks
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not about multiplication. It's about double. In Java, double is represented by the means of IEEE754 standard. The value is just an approximation.
You can check it on this site (or any similar, there are plenty): http://www.h-schmidt.net/FloatConverter/
 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, this was helpful
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!