Invalid octal digit error

15,798

Solution 1

Octal numbers use the digits 0 to 7. Maybe the error could be the digit 9, and digit 8 in your number. If you want to pass the number '962833', try converting it first to a correct octal number with an online converter. Then add the leading '0' and pass it to your function.

Solution 2

0962833 is an octal number because of the leading zero, so you can't have digits higher than 7. If you need the leading zero, why can't you turn it into a string? Leading zeroes have no mathematical significance, so why should there be a way to represent them in a numerical type?

Share:
15,798
Paz Aricha
Author by

Paz Aricha

Updated on June 11, 2022

Comments

  • Paz Aricha
    Paz Aricha almost 2 years

    Invalid octal digit error in Ruby, how do I by pass that? I have a number, 0962833, which I need to send to an API but I can't send it since I get this invalid octal digit error.

    I need a work around for that without turning that number into a string, the zero can't be removed, it's a must.

  • Michael Kohl
    Michael Kohl almost 12 years
    There's no need for an online converter: "0962833".to_i(10).to_s(8) => "3530421" :-)
  • Paz Aricha
    Paz Aricha almost 12 years
    You guys are right, it wasn't a number issue since I change it to a string, the problem was with my curl command. Thanks.