wood burning stoves
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: 42958
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: float values
It's not a secret anymore!