Basic Data Types

Learn how to represent and store numbers and text in Kotlin.

Kotlin is a statically typed language, meaning that the data type of every expression is known at compile time.

Integers #

There are four basic data types to store integer numbers of different sizes in Kotlin:

Press + to interact
val byte: Byte = 127
val short: Short = 32767
val int: Int = 2147483647
val long: Long = 9223372036854775807

Note: The values assigned to each variable above are the largest allowed for the corresponding data type. This gives you an indication of their magnitude.

If you increase the assigned values even by one, the Kotlin compiler will complain because an overflow would occur at runtime (try it!).

Floating Point Numbers #

Additionally, Kotlin has Float and Double to store floating point numbers up to different precision and sizes: ...