In this category, Kotlin provides two data types:
- Float
- Double
These data types can store values containing decimal places. Float and Double are the floating point data types that are used to store real number values. A Float can contain 4 bytes of information, while the Double data type can handle 8 bytes. Kotlin allows us to handle scientific notation with the Double data type as follows:
- Create two Double types of variables as follows:
- Create d1 with an explicit declaration of the data type
- Create d2 with an implicit declaration:
fun main(args: Array<String>) {
var d1 : Double = 7.20E15 // Scientific calculation
var d2 = 7.20e-15
- Assign scientific values to both variables and print:
println("Value of d1 = " + d1 + " and Value of d2 = " + d2)
}
The Value of d1 = 7.02E15 and Value of d2 = 7.02E-15 printed values are the same, except the value of d2 is capitalized.