I saw someone, I think it was s.o.s, recommend the use of BigDecimal to someone else. So out of curiosity, and having heard of BigDecimal before, I looked at the Javadoc to see how large the values it could hold were and how it held them. From the doc:

"Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore (unscaledValue × 10-scale). "

What does an unscaled value refer to? One that hasn't been correctly sized, and therefore doesn't represent anything in its present state? It seems like whats above could be referring to, lets say we had unscaled value = 123456789 and scale = 5. Then the BigDecimal would treat the scaled version as 123456789.00000? And if scale = -5 it'd be 1234.56789? Is that correct? And how does BigDecimal store numbers?

Recommended Answers

All 3 Replies

I think it is Standard Form. e.g 0.00000864 is 8.64 × 10^-6

That doesn't make sense because the Javadoc says that it is an integer. 8.64 is not an integer.

precision integer unscaled value and a 32-bit integer scale

zero or positive, the scale is the number of digits to the right of the decimal point

in other words, a mantissa and an exponent - standard form.

e.g 4 x 10^ 8

the arbitary value (the 4) and the scale (the 8)
each part is stored as a seperate integer

which means the big int in my example is 400,000,000

computers do floating point the same way as mentioned in #2

http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.