Kotlin has the same variable types we use in programming but the way we initialize them is a bit different from normal i.e., traditional way of declaring in java.

Let’s have a look at the continuation of the previous tutorial on android Kotlin variables. We have learnt about String, Integer declarations previously now will look at more variables in this tutorial. May have a look at the previous tutorial

Android Kotlin Variables Declaration || Kotlin Tutorial 2


Double Variable

Double variable is represented with 64 bits. This variable is much more precisely used for representing the accurate amount in terms of decimal values in necessary scenarios.

When we want to show the marks of the person we say 56 or 73 …

But when we want to show the average of all the marks then we will get a decimal value for sure we cannot represent is in Integer format as it gets round up excluding after decimal values.





Float Variable

Float variable is represented with 32 bits. And yes its a light weight format of representing decimal values compared to double.

They same implementation as of double but double has more precision than float which means an accurate answer including more decimal values can be observed using double.






Double Or Float ?

After going through the tutorial you may get this doubt for sure, both double and float have their own importance.

Sometimes you may not require much decimal values and may be satisfied which less decimal representation the you may go for float.

-> The main advantage of using float is it’s memory usage floats can represent decimal values up to 7 digits of precision.

-> The main advantage of double is it’s precision it can represent 16 digits of precision.


So the conclusion is if you have a memory constraints / limits or you need a faster processing then go for float else you need precision i.e., accurate results then go for double.


For more details visit this video tutorial.

Show Buttons
Hide Buttons
Read previous post:
Fetch Values from MYSQL Using PHP