Ranges in Kotlin using data type Double

后端 未结 3 1012
無奈伤痛
無奈伤痛 2020-12-20 12:21
    fun calcInterest(amount: Double, interest: Double): Double {
    return(amount *(interest/100.0))
}

fun main(args: Array) {

    for (i in 1.0..2.         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-20 12:40

    According to the documentation for ranges:

    Floating point numbers (Double, Float) do not define their rangeTo operator, and the one provided by the standard library for generic Comparable types is used instead:

    public operator fun > T.rangeTo(that: T): ClosedRange
    

    The range returned by this function cannot be used for iteration.

    You will have to use some other kind of loop since you can't use ranges.

提交回复
热议问题