kotlin Number to Long
fun main() {
val number: Number = 42
val longValue: Long = number.toLong()
println("Original number: $number")
println("Converted to Long: $longValue")
}
Explanation:
- Declare a variable
number
of typeNumber
and assign it the value42
. - Declare a variable
longValue
of typeLong
and assign it the result of converting thenumber
to aLong
using thetoLong()
method. - Print the original number and the converted Long value using
println()
.