- Integers (no fractional part) :
Byte
,Short
,Int
,Long
- Floating Point (with fractional part) :
Float
,Double
fun main() {
val byte: Byte = 1 // Size = 1B, Range = -128..127
val short: Short = 1000 // Size = 2B, Range = -32k..32k
val int = 5 // Size = 4B, Range = -2e9..2e9
val long = 5L // Size = 8B, Range = -9e18..9e18
val float = 3.14f // Size = 4B, upto 7 decimal digits
val double = 3.14 // Size = 8B, upto 16 decimal deigits
}
Note that L
is used to define Long
, f
is used to define Float
and decimal point number without f
is inferred as Double
.
-
We can assign numerical values in hexadecimal and binary format using
0x
and0b
prefix :fun main() { val bin = 0b101 // Binary number val hex = 0xFF // Hexadecimal number println(bin) // Prints "5" println(hex) // Prints "255" }
-
To represent large numbers in a readable way, we can use underscores
_
as :val billion = 1_000_000_000