Consider:
val foo: Int = 1 foo.toDouble() // ok val bar = 2.toUInt() bar.toDouble() // error!
This doesn't make sense to me. Why wouldn't UInt have toDouble
? (it also doesn't have .toFloat
).
The docs say:
Every number type supports the following conversions:
- toByte(): Byte
- toShort(): Short
- toInt(): Int
- toLong(): Long
- toFloat(): Float
- toDouble(): Double
- toChar(): Char
So it should be possible. The error I get is:
Error:(11, 4) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: @InlineOnly public inline fun String.toDouble(): Double defined in kotlin.text
Is UInt not considered a number type? Or is it something else?
This appears to be coming in 1.3.30, according to this YouTrack request.
1.3.30 was just recently tagged and appears to be releasing very shortly.
Is UInt not considered a number type?
Yes, it doesn't extend Number
class.
Declaration of Int
:
class Int : Number, Comparable<Int>
Declaration of UInt
:
inline class UInt : Comparable<UInt>
Starting with Kotlin version 1.3.30 UInt
has toFloat
and toDouble
methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With