This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes precision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "precision" Watch "precision" New topic
Author

precision

Neha Mittal
Greenhorn

Joined: Dec 05, 2008
Posts: 10
What does "loss of Precision" mean?
(This is the thing I came across while studying 'Float' integer literals)


Dreams are not which you see when you are asleep. Dreams are that that do not let you sleep..
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

The float and double types can store floating-point numbers, but not with infinite precision. A float has about 6 or 7 decimal digits of precision, and a double has 15 or 16 decimal digits.

A floating-point literal in Java is by default a double. So you will get a "possible loss of precision" error if you do something like this:

float pi = 3.14159265358979;

You can add a letter "f" or "F" to make a floating-point literal a float:

float pi = 3.151593f;

(Note, it makes no sense to specify more than 7 digits for a float, because they won't fit into the float anyway).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Neha Mittal
Greenhorn

Joined: Dec 05, 2008
Posts: 10
Thanks jesper!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: precision