/** * Returns a {@code BigDecimal} which is numerically equal to * this one but with any trailing zeros removed from the * representation. For example, stripping the trailing zeros from * the {@code BigDecimal} value {@code 600.0}, which has * [{@code BigInteger}, {@code scale}] components equals to * [6000, 1], yields {@code 6E2} with [{@code BigInteger}, * {@code scale}] components equals to [6, -2] * * @return a numerically equal {@code BigDecimal} with any * trailing zeros removed. * @since 1.5 */ public BigDecimal stripTrailingZeros() { this.inflate(); BigDecimal result = new BigDecimal(intVal, scale); result.stripZerosToMatchScale(Long.MIN_VALUE); return result; }
/** * Returns a {@code BigDecimal} which is numerically equal to * this one but with any trailing zeros removed from the * representation. For example, stripping the trailing zeros from * the {@code BigDecimal} value {@code 600.0}, which has * [{@code BigInteger}, {@code scale}] components equals to * [6000, 1], yields {@code 6E2} with [{@code BigInteger}, * {@code scale}] components equals to [6, -2] * * @return a numerically equal {@code BigDecimal} with any * trailing zeros removed. * @since 1.5 */ public BigDecimal stripTrailingZeros() { this.inflate(); BigDecimal result = new BigDecimal(intVal, scale); result.stripZerosToMatchScale(Long.MIN_VALUE); return result; }
if (quotient.scale > 0) { quotient = quotient.setScale(0, RoundingMode.DOWN); quotient.stripZerosToMatchScale(preferredScale);
if (quotient.scale > 0) { quotient = quotient.setScale(0, RoundingMode.DOWN); quotient.stripZerosToMatchScale(preferredScale);
Math.min(precisionDiff, preferredScale - result.scale) ); } else { result.stripZerosToMatchScale(preferredScale); return result;
Math.min(precisionDiff, preferredScale - result.scale) ); } else { result.stripZerosToMatchScale(preferredScale); return result;
new BigDecimal(result.intVal, result.intCompact, result.scale, 0); scaledResult.stripZerosToMatchScale(preferredScale); return scaledResult; } else { // result.scale < preferredScale
new BigDecimal(result.intVal, result.intCompact, result.scale, 0); scaledResult.stripZerosToMatchScale(preferredScale); return scaledResult; } else { // result.scale < preferredScale
res.stripZerosToMatchScale(preferredScale); return res;
res.stripZerosToMatchScale(preferredScale); return res;