Basic Data Type - Kotlin

Watch this here

Data types :

In Kotlin we don't need to provide data type explicitly(most of the time) for the variables. According to the value of the variable data type is taken by kotlin itself.

    Boolean // true or false
    Byte    // can have values from -128 to 127
    Short   // can have values from -32768 to 32767
    Int     // can have values from -2147483648 to 2147483647
    Long    // can have values from -9223372036854775808 to 9223372036854775808
    Float   // double-precision 64-bit floating point.
    Double  // double-precision 32-bit floating point.
    Char    // can have only one character
    Strings // it can store character array

Types conversion :

We can use the keyword "as"(Unsafe cast operator) to convert a value from one type to others. If the conversion is not possible then we will get an exception. Also we have some internal conversation methods like "toStirng()", "toDouble()" ,"toLong()" , "toInt()" and many more.

    println("5".toInt())                //print 5
    println("5".toLong())               //print 5
    println("5".toFloat())              //print 5.0
    println("5".toDouble())             //print 5.0
    println("5.1234567890".toFloat())   //print 5.123457
    println("51234567890".toDouble())   //print 5.123456789E10);

12700 Subscribers