• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

precision

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "loss of Precision" mean?
(This is the thing I came across while studying 'Float' integer literals)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Neha Mittal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks jesper!!
reply
    Bookmark Topic Watch Topic
  • New Topic