Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the underscore mean in literal numbers?

Tags:

ruby

What does that mean?
0.0..10_000.0

like image 857
auralbee Avatar asked Feb 09 '11 14:02

auralbee


People also ask

What does an underscore number mean?

Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this: x = 1_000_000. is interpreted to be the same as this: x = 1000000.

In which of the following usage of underscore is incorrect?

You cannot use underscore at the beginning or end of a number. You cannot use underscore adjacent to a decimal point in a floating point literal. You cannot use underscore in positions where a string of digits is expected.

What is the maximum number of underscore character?

Explanation: Theoretically, there is no limit on the number of underscores. 17) Java uses UTF-16 Unicode format to represent characters.

What does an underscore mean in Java?

JavaObject Oriented ProgrammingProgramming. In earlier versions of Java, the underscore ("_") has used as an identifier or to create a variable name. Since Java 9, the underscore character is a reserved keyword and can't be used as an identifier or variable name.


2 Answers

Underscores are ignored. You can put them in to make them more readable.

like image 188
Kyle Heironimus Avatar answered Oct 09 '22 09:10

Kyle Heironimus


It’s just a syntax convenience to separate the thousands:

$ ruby -e 'puts 1_000 + 1_000_000'  #=> 1001000 
like image 44
zoul Avatar answered Oct 09 '22 10:10

zoul