ruby 1.8.0: Error on "%02d" % "08" or "%02d" % "09"

T

Thomas Link

Hi,

I'm using ruby 1.8.0 (Win native and cygwin version). These two commands

"%02d" % "08"
"%02d" % "09"

result in the error

`%': invalid value for Integer: "08" (ArgumentError)

For other numbers/strings (including "8" and "9", but also "01".."07",
it appears to work as expected -- i.e., as I would expect it.

The problem, I want to solve: Turn strings like "1", "3", "04", "03"
into a canonical 2-digit string with zeros in front. Should I use a
different method?

Cheers,
Thomas.
 
T

ts

T> "%02d" % "08"

it think that you are trying to give it an octal number, try

"%02d" % "08".to_i

T> "%02d" % "09"


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top