fun calcInterest(amount: Double, interest: Double): Double {
return(amount *(interest/100.0))
}
fun main(args: Array) {
for (i in 1.0..2.
As of Kotlin 1.1, a ClosedRange "cannot be used for iteration" (rangeTo() - Utility functions - Ranges - Kotlin Programming Language).
You can, however, define your own step extension function for this. e.g.:
infix fun ClosedRange.step(step: Double): Iterable {
require(start.isFinite())
require(endInclusive.isFinite())
require(step > 0.0) { "Step must be positive, was: $step." }
val sequence = generateSequence(start) { previous ->
if (previous == Double.POSITIVE_INFINITY) return@generateSequence null
val next = previous + step
if (next > endInclusive) null else next
}
return sequence.asIterable()
}
Although you can do this if you are working with money you shouldn't really be using Double (or Float). See Java Practices -> Representing money.