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

Computers & Internet

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

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