aspose file tools*
The moose likes Beginning Java and the fly likes Single precision /double precision? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Single precision /double precision?" Watch "Single precision /double precision?" New topic
Author

Single precision /double precision?

Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
I have an idea as to what float and double are all about.
But dont understand what single precision and double precision mean.
How does one limit the accuracy of double variables to .........say 6 decimal places.

[ UD: removed superfluous duplicated questions marks ]


From The Demon,
with love.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
You can't limit the precision (not "accuracy") of a double to 6 significant [decimal] figures. A normalised double uses 53 bits of precision, which is 53 * log2 = 15.96 decimal places.
You can print out a double with the %e tag; you will have to check its details in Formatter, but you can probably get that to display 6 sig fig.

A double is classed as double-precision, using 64 bits; there are specifications for quadruple-precision floating point numbers (128 bits, not used in Java) and single-precision (32 bits, called float in Java). A normalised float has 24 bits' precision which is equivalent to 7.3 [decimal] significant figures, so that might solve your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Single precision /double precision?