Learning numeric literals

Unlike Java, Kotlin does not support octal literals (which begin with 0 in Java) as a numeric literal. The following numeric literals are supported:

  • Decimals: We have the following decimals:
    • Int: 123
    • Long: 123L ends with a capital L
  • Hexa-decimals: Begin with a 0x followed by the value. An example is 0xCAFE for the decimal value 51966.
  • Binary: Begins with prefix 0b followed by the value. An example is 0b1010 for the decimal value 10.

  • Floating point: Kotlin supports conventional notations for floating points:
    • Double:123.0, 12.0e10
    • Float: 123.0f or 123.0F ends with capital F or simple f 

All numeric literals can use _ to separate digits. Some examples are 100_000_000, 0xA_B_C, 0b000_000_001100_000F.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.134