ara.t.howard / noaa.gov wrote:

> On Sat, 19 Aug 2006, Wes Gamble wrote:
> 
>> All,
>>
>> Why does this fail?
>>
>> irb(main):009:0> sprintf("%d", '08')
>> ArgumentError: invalid value for Integer: "08"
>>        from (irb):9:in `sprintf'
>>        from (irb):9
[...]
>> But I'm telling sprintf to interpret it as decimal, so why can't I have
>> leading zeroes?
>>
>> Please explain to me how this is expected behavior.
[...]
> because:
[...]
> ruby uses 'Integer(s)' to convert strings to ints and
[...]
> Kernel#Integer
[...]
>          If _arg_ is a +String+, leading radix indicators (+0+, +0b+, and
>          +0x+) are honored.
[...]
> so it's expected, documented, and consistent with c.

It is not expected, nor documented, because the documentation of sprintf 
says:
              d   | Convert argument as a decimal number.

...which is very explicit in that the argument will be interpreted as a 
decimal number, not octal.

Greetings.