Isn't 00.0 the same as 0.0?

I just found a strange problem in the ruby ​​of a programming language, this is not a big problem, but I just can not understand why this is happening. I would be interested if someone knows the problem for my problem.

In ruby ​​you can write 0 or 00 , it does not matter, it comes to the same result.
If you run 0 === 00 , you will also get true , which means the two inputs are the same.

0.0 also 0 , so logically 00.0 should also be 0.0 , but the problem is that if you try to use the number 00.0 , then you will get an error. If you run, for example:

 a = 00.0 

You will get this error:

syntax error, unexpected tINTEGER

Of course, I know that this is a small problem, but, as I said, I would like to understand why the computer does not treat 00.0 as well as 0.0 ?

+8
ruby numbers
source share
2 answers

The fact is, when parsing and ruby ​​find that a number with more than two digits starts with the character 0, it analyzes it as an octal integer. So when he parses 00, it is 0 in octal, which is 0 in decimal. But if he finds. then this is an invalid integer and this is the error it shows.

+4
source share

I tried "a = 00.0" at http://tryruby.com and got:

 SyntaxError: no .<digit> floating literal anymore put 0 before dot. near line 1: "" 

Obviously, Ruby vocabulary does not expect such a form of float.

+1
source share

All Articles