Reputation: 643
I'm a newbie in kotlin.
I was running the below code to understand how BigDecimal works, but i'm missing something on how to safely exit from intellij terminal after entering the input. I always get NumberFormatException
if i don't enter anything and press Enter key. How to quit safely and see the result.
import java.math.BigDecimal
fun main(args: Array<String>) {
val input = generateSequence { readLine() }
println(input
.map { it.toBigDecimal() }
.fold(0.toBigDecimal()) { a, b -> a + b })
}
Source https://medium.com/@elizarov/floating-point-for-decimals-fc2861898455
Upvotes: 0
Views: 443