Why is 032 different than 32 in Ruby?

前端 未结 4 618
一生所求
一生所求 2021-01-07 10:17

I have noticed Ruby behaves differently when working with 032 and 32. I once got syntax errors for having 032 instead of just 32 in my code. Can someone explain this to me?

4条回答
  •  难免孤独
    2021-01-07 10:54

    i don't know about syntax errors, but when you prefix a number with zero it means it's octal (base-8)... so 032 is actually 26 in decimal

提交回复
热议问题