IBM

Decimal arithmetic for Java[TM]

(Software version 1.08 – 6 Sep 2000)
Computer systems can provide an arithmetic that gives the results that people expect, instead of the results that binary floating point calculations give (see the sidebar on the right for an example). This is not available in Java today, so a decimal floating point arithmetic is needed – one which gives the same results as the arithmetic that people learn at school (see the Decimal Arithmetic FAQ for more details).

This site describes an enhanced BigDecimal class (com.ibm.math.BigDecimal) for Java, which is the basis for a proposed enhancement to java.math.BigDecimal. Please see the Java Specification Request (JSR) for details of the proposal. This JSR is proceeding to plan; you can find changes from this design in the Decimal Arithmetic Enhancement Public Review Draft.

The com.ibm.math.BigDecimal class (and its supporting class, MathContext) is fully implemented and is available below, and is also included with IBM's Java developer kits as of version 1.1.8.

The new class extends the existing class with the floating point arithmetic from ANSI X3.274, which does arithmetic the way people do. This makes it especially easy to add human-oriented arithmetic to your applications.


Here, you'll find:
  • Decimal Arithmetic for Java Frequently Asked Questions (FAQ).
  • Detailed Acrobat format documentation for the decimal arithmetic classes (including background information and design notes). This is also available on the World Wide Web in HTML format.
  • A sample application.
  • The package for download (includes the compiled classes, the FAQ, detailed documentation, and sample application).
  • The open source files for the two classes are included in the ICU4J download.
  • The class documentation in javadoc format, downloadable as decjdoc.zip – unzip and then view index.html. Or google ‘ICU4J BigDecimal’.
And see also the related links on the Standard Decimal Arithmetic page.
Divide 9 by 10 repeatedly...
Decimal:
 0.9
 0.09
 0.009
 0.0009
 0.00009
 0.000009
 9E-7
 9E-8
 9E-9
 9E-10
    

Binary:
 0.9
 0.089999996
 0.0090
 9.0E-4
 9.0E-5
 9.0E-6
 9.0000003E-7
 9.0E-8
 9.0E-9
 8.9999996E-10
    

Copyright © IBM Corporation 1998, 2002. All rights reserved.
Java is a trademark of Sun Microsystems Inc.
think 10

[ IBM home page | Search | Contact IBM | Help | Terms of use | Privacy ]