diff --git a/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt b/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt index a3ab1aab..3c20d1ab 100644 --- a/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt +++ b/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt @@ -1289,16 +1289,17 @@ class BigDecimal private constructor( newExponent-- } val exponentModifier = result.numberOfDecimalDigits() - resolvedDecimalMode.decimalPrecision + val discarded = divRem.remainder * other.significand return if (usingScale) { BigDecimal( - roundDiscarded(result, divRem.remainder, resolvedDecimalMode), + roundDiscarded(result, discarded, resolvedDecimalMode), newExponent + exponentModifier, resolvedDecimalMode.copy(decimalPrecision = result.numberOfDecimalDigits()) ) } else { BigDecimal( - roundDiscarded(result, divRem.remainder, resolvedDecimalMode), + roundDiscarded(result, discarded, resolvedDecimalMode), newExponent + exponentModifier, resolvedDecimalMode ) diff --git a/bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/decimal/ReportedIssueReplicationTest.kt b/bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/decimal/ReportedIssueReplicationTest.kt index b744f89f..32e61b87 100644 --- a/bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/decimal/ReportedIssueReplicationTest.kt +++ b/bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/decimal/ReportedIssueReplicationTest.kt @@ -352,4 +352,12 @@ class ReportedIssueReplicationTest { rounded ) } + + @Test + fun roundHalfAway() { + val result = BigDecimal.fromInt(2) + .divide(BigDecimal.fromInt(3), DecimalMode(2, RoundingMode.ROUND_HALF_AWAY_FROM_ZERO)) + .doubleValue(false) + assertEquals(0.67f, result.toFloat()) + } }