In a Ruby on Rails app, we have some details which are stored as an Integer, but are being interpreted as hex when we’re trying to convert to string.
e.g.
> 0123.to_s
=> 83
Is there a way of treating the value as an integer, even though it’s in a format that Ruby sees as hex. If there isn’t we’ll just change the database field to varchar!
Actually, that’s not hexadecimal, that’s octal. If you don’t want this behavior, don’t put a leading zero on your integer literals in code:
If the leading zero is appearing because you’re using Ruby to create aligned Ruby code using printf, like so:
…then instead use spaces for padding rather than zeros: