ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
350 stars 41 forks source link

Add stripTrailingZeros() method #311

Open morale3232 opened 1 month ago

morale3232 commented 1 month ago

Is your feature request related to a problem? Please describe. The java.math.BigDecimal class has a stripTrailingZeros() method that would be nice to have in this implementation.

Describe the solution you'd like I'd love to see the same method implemented in the same fashion.

Describe alternatives you've considered I've written a small helper function that takes the string representation of the BigDecimal and manually removes all trailing zeros, but I would prefer to have the official method.

Additional context


    public BigDecimal stripTrailingZeros() {
        if (this.intCompact != 0L && (this.intVal == null || this.intVal.signum() != 0)) {
            return this.intCompact != Long.MIN_VALUE ? createAndStripZerosToMatchScale(this.intCompact, this.scale, Long.MIN_VALUE) : createAndStripZerosToMatchScale(this.intVal, this.scale, Long.MIN_VALUE);
        } else {
            return ZERO;
        }
    }