>>>I have a bigdecimal and a double value,say
>>>
[quoted text clipped - 21 lines]
> bigdecimal to double i fear of inaccuracy(In cases where i deal with
> huge values greater than double)
You won't be dealing with values greater than double, because the
maximum double is bigger than 10^308. That is more than the probable
number of atoms in the observable universe.
However, it is entirely possible that you could get a wrong answer for
the least significant digit on large sums of money. Double is just about
precise enough to get the cents digit right on the US national debt in
dollars. If that is good enough, one solution might be to use double for
the exponentiation, but immediately convert back to BigDecimal. That
would avoid accumulating rounding errors during routine addition and
subtraction.
I'm a bit surprised by the use of exponentiation in this precise an
environment. For example, I would have expected compound interest to be
done a compounding period at a time, with the interest for each period
rounded according to fixed rules, then added to the balance.
Patricia
Chris Uppal - 20 Apr 2006 11:11 GMT
> I'm a bit surprised by the use of exponentiation in this precise an
> environment. For example, I would have expected compound interest to be
> done a compounding period at a time, with the interest for each period
> rounded according to fixed rules, then added to the balance.
Another possibility is that "perfect" precision is not required for /this
particular/ calculation. For instance in the UK any offer of a loan must be
accompanied by (besides the exact statement of interest, etc) an indicator
figure which is supposed to make it easier for people to compare offers with
different conditions. I forget the thing's name, and the rules for computing
it are complicated, but the point is that floating-point accuracy is entirely
adequate, even though it's a financial calculation.
-- chris
> iam writing code for some banking applications which demand accuracy
>in money
>values.For money values iam using Bigdecimal. If i convert my
>bigdecimal to double i fear of inaccuracy(In cases where i deal with
>huge values greater than double)
Hmm. What you might do is get a good initial approximation with
Math.pow on double. Then use a Newton-Raphson to home in on a very
accurate value.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.