Double! implicitly converted to Int


#1

If you have a Double! and you compare it to an Int, it acts like Kotlin converts the Double! to Int first (truncating it), and then compares. Consider the following example:

Java:
public class Holder {
private Double value;
public Holder(Double value) { this.value = value; }
public Double getValue() { return value; }
}

Kotlin:
fun main(args : Array) {
val j = Holder(0.99)
println(“j.value > 0 = {j.value > 0}") println("j.value > 0.0 = {j.value > 0.0}”)
}

This prints:
j.value > 0 = false
j.value > 0.0 = true

Is this a bug or by design?


#2

For me it looks like a bug. I’ve filed an issue https://youtrack.jetbrains.com/issue/KT-11514.
Thanks for the report.