BigDecimal : Java Glossary

go to home page B words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 Roedy Green, Canadian Mind Products
BigDecimal
java.math.BigDecimal provides for immutable arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value (a BigInteger 2’s complement variable length array of bytes) and a non-negative 32-bit integer scale, which represents the number of digits to the right of the decimal point. Scales may not be negative. That allows you to work with decimal fractions of arbitrary precision.

To convert a long to a BigDecimal use:

// convert a long to BigDecimal, with some implied decimal places.
BigDecimal d = BigDecimal.valueOf( theLong, decimalPlaces );

You can’t use ordinary arithmetic or comparison operators on BigDecimal. You must use methods like BigDecimal.add, .subtract, .multiply,. divide, .pow, .abs, .compareTo

To convert your BigDecimal to a String for display you can use BigDecimal. toString or BigDecimal. toEngineeringString. It is also possible using Formatter and printf.

Learning More

Sun’s Javadoc on BigDecimal class : available:
Arcimath
BigInteger
DecimalD Spec
gotchas
IBM’s BigDecimal: a cleanroom implementation of BigDecimal
PSPDec: Prospero Software Products Decimal

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/bigdecimal.html J:\mindprod\jgloss\bigdecimal.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.107]
You are visitor number 17,760.