August 2018
Beginner
178 pages
4h 56m
English
Numbers in Kotlin can be represented with integer types and floating point number types. Integer types are Byte, Short, Int, and Long.
Floating point number types are Float, and Double.
The following table shows all the number types with their memory sizes and default values:
|
Type
|
Size
|
Default Value
|
|
Byte
|
8 bit
|
0
|
|
Short
|
16 bit
|
0
|
|
Int
|
32 bit
|
0
|
|
Long
|
64 bit
|
0L
|
|
Float
|
32 bit
|
0.0F
|
|
Double
|
64 bit
|
0.0D
|
The following example shows how to initialize number types with literals:
val long: Long = 9999Lval int: Int = 999val short: Short = 99val byte: Byte = 9val float: Float = 9.99Fval double: Double = 9.99999
Kotlin also allows the use of hexadecimal and binary numbers in literals:
Read now
Unlock full access