Error: Overload Resolution Ambiguity in Kotlin

Viewed 190

I have this function.

fun BigDecimal.percent(percentage: Float) = this.multiply(percentage.toBigDecimal()).divide(BigDecimal(100))

Calling the function :

somelist.size?.toBigDecimal()?.percent(numString.toFloat())

value of numString is "50" or "75"

On calling this function I'm getting compile error :

error: overload resolution ambiguity:
public inline fun Int.toBigDecimal(): BigDecimal defined in kotlin
public inline fun Int.toBigDecimal(): BigDecimal defined in kotlin
somelist.size?.toInt()?.toBigDecimal()?.percent(

error: overload resolution ambiguity:
public inline fun Float.toBigDecimal(): BigDecimal defined in kotlin
public inline fun Float.toBigDecimal(): BigDecimal defined in kotlin
fun BigDecimal.percent(percentage: Float) = this.multiply(percentage.toBigDecimal()).divide(BigDecimal(100))

I'm not able to figure out what is the problem here. Any solutions or suggesstions please.

0 Answers
Related