Javatpoint Logo
Javatpoint Logo

Kotlin Type Conversion

Type conversion is a process in which one data type variable is converted into another data type. In Kotlin, implicit conversion of smaller data type into larger data type is not supported (as it supports in java). For example Int cannot be assigned into Long or Double.

In Java

In Kotlin

However in Kotlin, conversion is done by explicit in which smaller data type is converted into larger data type and vice-versa. This is done by using helper function.

The list of helper functions used for numeric conversion in Kotlin is given below:

  • toByte()
  • toShort()
  • toInt()
  • toLong()
  • toFloat()
  • toDouble()
  • toChar()

Kotlin Type Conversion Example

Let see an example to convert from Int to Long.

We can also converse from larger data type to smaller data type.

Next TopicKotlin Operator

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA