Why is (5_000_000 == 5000000) true | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is (5_000_000 == 5000000) true

The use of the underscore between digits

15th Jul 2021, 6:43 AM
Mickey
Mickey - avatar
3 Answers
+ 4
Mickey If you want to write lengthy numeric literals like that then use underscores. This feature was introduced in Java 7. That's for better readability.
15th Jul 2021, 6:56 AM
A͢J
A͢J - avatar
+ 2
5_000_000 is equivalent to 5,000,000 which is equivalent to 5000000 and hence true
15th Jul 2021, 6:51 AM
Rohit
+ 2
Mickey This feature is also present in Python. The Python interpreter seems to remove all the underscores present between two integers.
15th Jul 2021, 7:18 AM
Calvin Thomas
Calvin Thomas - avatar