@@ -55,10 +55,13 @@ import kotlin.reflect.full.withNullability
55
55
import kotlin.reflect.jvm.jvmErasure
56
56
import kotlin.reflect.typeOf
57
57
import kotlin.text.trim
58
+ import kotlin.toBigDecimal
58
59
import java.time.Instant as JavaInstant
59
60
import java.time.LocalDate as JavaLocalDate
60
61
import java.time.LocalDateTime as JavaLocalDateTime
61
62
import java.time.LocalTime as JavaLocalTime
63
+ import kotlin.toBigDecimal as toBigDecimalKotlin
64
+ import kotlin.toBigInteger as toBigIntegerKotlin
62
65
63
66
@PublishedApi
64
67
internal fun <T , C , R > Convert <T , C >.withRowCellImpl (
@@ -716,17 +719,25 @@ internal val defaultTimeZone = TimeZone.currentSystemDefault()
716
719
internal fun Number.toBigDecimal (): BigDecimal =
717
720
when (this ) {
718
721
is BigDecimal -> this
719
- is BigInteger -> BigDecimal (this )
720
- is Double -> BigDecimal .valueOf(this )
721
- is Int -> BigDecimal (this )
722
- is Long -> BigDecimal .valueOf(this )
723
- else -> BigDecimal .valueOf(this .toDouble())
722
+ is BigInteger -> this .toBigDecimalKotlin()
723
+ is Int -> this .toBigDecimalKotlin()
724
+ is Byte -> this .toInt().toBigDecimalKotlin()
725
+ is Short -> this .toInt().toBigDecimalKotlin()
726
+ is Long -> this .toBigDecimalKotlin()
727
+ is Float -> this .toBigDecimalKotlin()
728
+ is Double -> this .toBigDecimalKotlin()
729
+ else -> BigDecimal (this .toString())
724
730
}
725
731
726
732
internal fun Number.toBigInteger (): BigInteger =
727
733
when (this ) {
728
734
is BigInteger -> this
729
735
is BigDecimal -> this .toBigInteger()
730
- is Long -> BigInteger .valueOf(this )
731
- else -> BigInteger .valueOf(this .toLong())
736
+ is Int -> this .toBigIntegerKotlin()
737
+ is Byte -> this .toInt().toBigIntegerKotlin()
738
+ is Short -> this .toInt().toBigIntegerKotlin()
739
+ is Long -> this .toBigIntegerKotlin()
740
+ is Float -> this .roundToInt().toBigIntegerKotlin()
741
+ is Double -> this .roundToLong().toBigIntegerKotlin()
742
+ else -> BigInteger (this .toString())
732
743
}
0 commit comments