From: Carlos Date: 2006-08-19T10:19:36+09:00 Subject: Re: Bug in sprintf? [Hal Fulton , 2006-08-19 00.27 CEST] > Carlos wrote: > > > >> 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. > > The string of characters is interpreted as a decimal number IF IT IS > one. Since you started it with a zero, it's octal. It's a string... I wanted this string formatted as a decimal number. Just put these digits right justified in that other string. All this behind-the-scenes conversion to integer is an implementation detail I should not care about. For that conversion, #to_i could have been used as well, and then '09' would be interpreted as decimal 9. Why should I expect my string to be passed through Integer() before formatting? That is not documented. So, I expected sprintf "%02d", "09" # => "09" I see that none of you (except Wes) expected that, so, OK, my expectations should be wrong. I really didn't expect _that_ (but I'm bad on expectations :), I supposed that my expectations would be the majority, or that at least 50% would expect something like #to_i. But everyone expected Integer() and Integer() is what is used, and this took nobody by surprise, so it's OK, I guess :) Greetings.