Good afternoon, below I’ve attached source code of overloading of divide operator for BigDecimal.
public inline operator fun BigDecimal.div(other: BigDecimal):
BigDecimal = this.divide(other, RoundingMode.HALF_EVEN)
Was there any reason to use
BigDecimal::divide(BigDecimal divisor, RoundingMode roundingMode) instead of
This is not obvious, in my opinion, as it results in
12.0 / 100.0 = 0.0 instead of
12.0 / 100.0 = 0.12 if using BigDecimals.
I understand, that this may lead to
ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”, but in my opinion, this will be same way as for Java, and, therefore, more obvious.