File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes float values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "float values" Watch "float values" New topic
Author

float values

Nila dhan
Ranch Hand

Joined: Sep 15, 2005
Posts: 160
Hi guys,could anyone make me clear about this.
If i declare a variable like this, float a=1; it compiles without any error.But if i say float a=1.0 the following compliation error occurs "possible loss of precision" why is is?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
That's because a value like "1.0" is considered to be a double. If you're certain that it's a float (and that's a safe assumption in this case), write it like "1.0f" or "1.0F". That indicates that it should be treated like a float.


Ping & DNS - my free Android networking tools app
muhsin sabeer
Ranch Hand

Joined: Oct 01, 2005
Posts: 35
The default data type for floating literal is double. So, when u declare float literal and assign double value should cause that error. E.g.,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: float values