In Kotlin everything is an object.
The built-in number types are as follows:
Type | Width |
---|---|
Long | 64 |
Int | 32 |
Short | 16 |
Byte | 8 |
Double | 64 |
Float | 32 |
To create a number literal, use one of the following forms:
fun main(args: Array<String>) { val int = 123 val long = 123456L val double = 12.34 val float = 12.34F val hexadecimal = 0xAB val binary = 0b01010101 /*from www . j a v a2 s.c o m*/ println(int) println(long) println(double) println(float) println(hexadecimal) println(binary) }
A long value requires the suffix L and a float, the suffix F.
The double is used as the default for floating point numbers, and int for integral numbers.
The hexadecimal and binary use the prefixes 0x and 0b respectively.