This is the Jdk7-b147 version of BigDecimal.doubleValue()
public double doubleValue(){
if (scale == 0 && intCompact != INFLATED)
return (double)intCompact;
// Somewhat inefficient, but guaranteed to work.
return Double.parseDouble(this.toString());
}
They admit that this way is inefficient! Is there a better/faster way than to use this method?
BigDecimal
to adouble
is hard. (That said, I've got a JDK patch pending review to speed upBigInteger.doubleValue()
by a little over two orders of magnitude.)BigInteger.{float,double}Value()
. The logic forDouble.parseDouble
, which is nearly the same as what you'd need to convertBigDecimal
todouble
, is insun.misc.FloatingDecimal
-- you can see how messy it is there.