Floating Point Numbers
In Kotlin, Float and Double are the two numeric types that can represent decimal numbers. These numbers are also called “floating point numbers” because the decimal point can appear in any position – that is, the decimal point is “floating” (as opposed to being fixed) – depending on the number’s order of magnitude.
The name Double is short for “double-precision floating point number.” Doubles use twice as many bits as a regular Float, hence the name, and can store decimal numbers more accurately.
Floating point numbers in Kotlin can also take on special values for infinity, negative infinity, and NaN
– short for “not a number.” These values are typically returned when performing illegal or undefined operations, ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.