private String toStringWithBigDecimal() { StringBuilder buffer = new StringBuilder(); BigDecimal bigDecimal = bigDecimalValueNoNegativeZeroCheck(); String significand = bigDecimal.unscaledValue().abs().toString();
/** * Gets a BigDecimal that is equivalent to this Decimal128. * * @return a BigDecimal that is equivalent to this Decimal128 * @throws ArithmeticException if the Decimal128 value is NaN, Infinity, -Infinity, or -0, none of which can be represented as a * BigDecimal */ public BigDecimal bigDecimalValue() { if (isNaN()) { throw new ArithmeticException("NaN can not be converted to a BigDecimal"); } if (isInfinite()) { throw new ArithmeticException("Infinity can not be converted to a BigDecimal"); } BigDecimal bigDecimal = bigDecimalValueNoNegativeZeroCheck(); // If the BigDecimal is 0, but the Decimal128 is negative, that means we have -0. if (isNegative() && bigDecimal.signum() == 0) { throw new ArithmeticException("Negative zero can not be converted to a BigDecimal"); } return bigDecimal; }
/** * Converts this {@code Decimal128} to a {@code double}. This conversion is similar to the <i>narrowing primitive conversion</i> from * {@code double} to {@code float} as defined in <cite>The Java™ Language Specification</cite>: if this {@code Decimal128} has * too great a magnitude to represent as a {@code double}, it will be converted to {@link Double#NEGATIVE_INFINITY} or * {@link Double#POSITIVE_INFINITY} as appropriate. Note that even when the return value is finite, this conversion can lose * information about the precision of the {@code Decimal128} value. Note that {@code #NEGATIVE_ZERO} is converted to {@code 0.0d}. * * @return this {@code Decimal128} converted to a {@code double}. * @since 3.10 */ @Override public double doubleValue() { if (isNaN()) { return Double.NaN; } if (isInfinite()) { if (isNegative()) { return Double.NEGATIVE_INFINITY; } else { return Double.POSITIVE_INFINITY; } } BigDecimal bigDecimal = bigDecimalValueNoNegativeZeroCheck(); if (hasDifferentSign(bigDecimal)) { return -0.0d; } return bigDecimal.doubleValue(); }
BigDecimal bigDecimal = bigDecimalValueNoNegativeZeroCheck(); BigDecimal otherBigDecimal = o.bigDecimalValueNoNegativeZeroCheck();