October 2018
Intermediate to advanced
370 pages
9h 15m
English
Similarly, we can convert a Double variable into an Integer. Use the toInt() function to convert from Double to Int as follows:
fun main (args: Array<String>) { var doubleValue : Double = 12.345 var intValue = doubleValue.toInt() println("From Double $doubleValue to Int $intValue")}
When converting from one type to another, we must take data loss into consideration. The following is the output of this example:
From Double 12.345 to Int 12
Double belongs to the real data type family. It can store values containing a decimal point. In contrast, Integer belongs to the number data type, which deals with whole numbers only. When the Double data type is converted to an Integer, the intValue variable simply ignores ...
Read now
Unlock full access