-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Hi,
I created some extension methods to convert BigDecimal to / from Java BigDecimal (see below).
Two questions here:
-
Are they correct and do you have any suggestions how to improve them (especially for converting from)?
-
If i give you a pull request with them, would you like to integrate it into the jvmMain branch of your library?
package net.dankito.banking.extensions
import com.ionspin.kotlin.bignum.integer.Sign
import java.math.BigDecimal
fun BigDecimal.toIonspinBigDecimal(): com.ionspin.kotlin.bignum.decimal.BigDecimal {
return com.ionspin.kotlin.bignum.decimal.BigDecimal.parseString(this.toString()) // TODO: couldn't figure out how to create BigDecimal from unscaledValue and scale
}
fun com.ionspin.kotlin.bignum.decimal.BigDecimal.toJavaBigDecimal(): BigDecimal {
val converted = BigDecimal.valueOf(this.significand.longValue(), (this.precision - this.exponent - 1).toInt())
if (this.significand.sign == Sign.NEGATIVE) {
return converted.negate()
}
return converted
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request