r/ProgrammerTIL • u/mishrabhilash • Nov 24 '17
Java [JAVA] TIL that you can declare numbers with underscores in them 10_000.
For better readability, you can write numbers like 3.141_592 or 1_000_000 (a million).
94
Upvotes
11
u/[deleted] Nov 25 '17 edited Nov 25 '17
To be precise - that isn't "declaring": in Java (and most other languages) a declaration means to introduce a variable for the first time and say what its type is. The correct term is "represent" or even just "write" (as you use in the second sentence).
Software engineering is a technical discipline and it's good to be accurate with your terminology! :-)
Also, you're going to confuse a lot of people with
3.14_15or1000_000. Most Java coding standards require them to be used every 3 digits or not at all, just like the comma in regular numbers. You'd find 1000,000 weird looking, and once you're used to this notation,1000_000looks just as weird.45
u/xDarkSadye Nov 24 '17
Probably clearer of you write a million like 1_000_000!
15
u/data1308 Nov 24 '17
Could you all please note, that an underscore is markdown for italics and escape them with backslashs (_)?
6
u/BigTunaTim Nov 25 '17
The latest version of C# supports this as well, fyi
2
u/jo-hirr Nov 25 '17
Like this:
http://en.cppreference.com/w/cpp/language/integer_literal
edit: formatting
-2
u/FUZxxl Nov 25 '17
It's Java, not JAVA. Java is not an acronym.