What if your numbers could talk to you clearly instead of hiding in a jumble of digits?
Why Number literal formats (underscore, hex, binary) in Kotlin? - Purpose & Use Cases
Imagine you need to write a long number like a credit card or a big binary value in your code. You type it all as one long string of digits without breaks.
Without clear formatting, it's easy to make mistakes like missing a digit or mixing numbers up. Reading and understanding these long numbers becomes tiring and error-prone.
Kotlin lets you write numbers with underscores to separate groups, and also supports hex and binary formats. This makes numbers easier to read and less likely to have mistakes.
val number = 1000000000 val flags = 15
val number = 1_000_000_000 val flags = 0b1111
You can write big or complex numbers clearly and safely, making your code easier to read and maintain.
When setting color codes in hex or configuring hardware flags in binary, using these formats helps you see exactly what values you are working with.
Underscores improve number readability.
Hex and binary formats let you write numbers in ways that match real-world uses.
This reduces errors and makes code clearer.