I am using ruby 1.9.3
Why Integer(“09”) throws “invalid value for Integer exception” in ruby while Integer(“07”) works pretty well?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because a leading zero is a common convention for octal (“base 8”) notation. There is no
9digit in octal, therefore it is a syntax error to use one.If you had written
Integer("014"), you would have gotten the number 12. (Therefore, do not use leading zeroes if you do not intend the octal notation.)