Did You Know In Kotlin You Can Use Underscores to Make Number More Readable?

Did You Know In Kotlin You Can Use Underscores to Make Number More Readable?

In Kotlin we can use (_) underscore characters to make the number more readable and clutter-less.

Generally, commas to separate numbers. Kotlin is one more step ahead, we can use underscore symbol (_) to separate the bunches in a large number.


Mathematical Operations in Kotlin


For example, you can define your number as:


val one_m = 1_000_000

And process normal mathemical operations on it.


/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
println("Hello, Factober!" + 10_00_000.div(2))
}

Underscores can be used in numbers in Kotlin Programming Language