File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "float values" Watch "float values" New topic

float values

Nila dhan
Ranch Hand

Joined: Sep 15, 2005
Posts: 161
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

Joined: Mar 22, 2005
Posts: 42965
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.
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.,
I agree. Here's the link:
subject: float values
It's not a secret anymore!