I got some weired problem while converting data type in ruby.
Here are some of the outputs that i got in console
0123 and enter gave me output 83
12345600.to_s #=> "12345600"
but
012345600.to_s gave me #=> "2739072" but i expect "012345600"
Seems like when there is 0 at the beginning of number the output is not as expected.
Can any one explain why this is happening? or provide me a solution so that i can get my expected output.
Thanks
Having a 0 at the start of a number makes the interpreter/compiler interpret the following digits as an octal number sequence (base 8) not a decimal number sequence (base 10). Therefore the number you entered is an octal number and not decimal.
You can test this on a scientific calculator by putting it into octal mode and then switching to decimal.