• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Storing floats and doubles

 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I understand it, Oracle stores floats and doubles as X.Y where X is the number of digits prior to the decimal point and Y is the number of decimal places after it. However, Java uses the IEEE 754 which stores: a sign bit, exponent, and fraction. How do you store these numbers without losing percision?
--Mark
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found http://www.csis.gvsu.edu/GeneralInfo/Oracle/java.920/a96654/ref.htm#1005984, which states:


IEEE 754 Floating Point Compliance
The arithmetic for the Oracle NUMBER type does not comply with the IEEE 754 standard for floating-point arithmetic. Therefore, there can be small disagreements between the results of computations performed by Oracle and the same computations performed by Java.
Oracle stores numbers in a format compatible with decimal arithmetic and guarantees 38 decimal digits of precision. It represents zero, minus infinity, and plus infinity exactly. For each positive number it represents, it represents a negative number of the same absolute value.
It represents every positive number between 10-30 and (1 - 10-38) * 10126 to full 38-digit precision.



How do other organizations deal with this?
--Mark
 
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you decide how much precision you need.
here the most precision is with exchange rates number(16,6)
I guess for scientific apps you may need more (especially with frequencies etc)
even so, 38 digits should cover all requirements!
reply
    Bookmark Topic Watch Topic
  • New Topic