Basic Types

Reading Time: < 1 minute

Kotlin is a statically typed programming language with basic data types support such as

  • Numbers
  • Characters
  • Boolean
  • Arrays
  • Strings

Statically typed programming language means that it does type checking. It knows the type of a variable at complie time, instead of runtime.
Numbers can be stored in type of
Type Allocated memory size
Double 64 bites
Float 32 bites
Long 8 bites
Int 4 bites
Short 2 bites
Byte 1 bites

Suppose you need to store 3.14 and the Euler’s number, than you can store it in a Float and in a Double.

Notice the “f” after 3.14. Kotlin, by default, interprest floating point numbers as Doubles, which have higher precision compared to Floats.

To declare a Float literal, you should explicitly tell the compiler that your value is Float by adding “f” at the end of the value.

To represent boolean values (true, false), the type Boolean is used.

In case if oyu need more precise result use Double insted of Float.  

3.33
3.33333333335

 

Follow and like us:
Click to rate this post!
[Total: 0 Average: 0]

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications