Originally posted by Rob Prime:

If you need decimal calculations this precise

Be careful about "precise" and "accurate".

The precision is the number of digits shown in the answer.

A rough definition of accuracy is the number of digits in the answer that are correct.

However, if floating-point arithmetic (double or float) has been used, then some of the digits may not be correct; the accuracy is often less than the precision. If many floating-point calculations are chained together carelessly, then most or all of the digits could be wrong!

BigDecimal can achieve almost unlimited precision and total accuracy; that is, all the digits are always correct. However, it is much slower, and uses much more storage than floating-point.

Note that BigDecimal can only do pow() with integer powers. There's no sqrt(), either. That's how it guarantees total accuracy.

Finally, note that Math.pow() is generally a bad way to compute integer powers, even when you are using floating-point. Unless your integer power is very large, you will likely get a better answer using multiplication. For example, for your z=x^12, you might do y=x*x*x, z=y*y*y*y.

[ June 23, 2008: Message edited by: Peter Chase ]