File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java Modulus operator

 
Babar Saeed
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i compile the following code
float f = 6.3f % 2.1f;
The answer must be 0.0.
but it's not.
but when i try this code
float f = 8.4f % 2.1f;
the answer is 0.0.
 
Lucas Richardson
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a loss of precision due to the fact that it can't represent the answer as a power of two. (rather than round, it tells you 2.0999999...). It's representative of the inaccuracy of computers when it comes to floating point numbers.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic