aspose file tools
The moose likes Java in General and the fly likes difference between float value  and float value with casting Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "difference between float value  and float value with casting" Watch "difference between float value  and float value with casting" New topic
Author

difference between float value and float value with casting

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689



what is the difference in these 2 statements ?what's happening in internally?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

The first 6.5 is a double, the round() that takes a double argument is invoked. The second one is a float, and the round() that takes a float is called. In both cases, the subtraction is done by the compiler at compile-time, so round() is invoked directly.

The reason the second one prints "false" is because a float is only 32 bits, and doesn't have the precision to distinguish between MIN_VALUE-6.5 and MIN_VALUE; they're not far enough apart on the number line. Double, on the other hand, is 64 bits, and can indeed distinguish between these values.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between float value and float value with casting
 
Similar Threads
Math class
Doubt in Math functions
Q on MIN/MAX_VALUE of Math class
Qn on abs () method
wrappers