A question about string#%

J

jun yu

I have an integer number like 1111, How can I get a string like below
by the string#% ?

"11110000"

I know "%-8d" % 1111 can get "1111 ".


Thank you.
 
H

Harry Kakueki

I have an integer number like 1111, How can I get a string like below
by =A0the string#% ?

"11110000"

I know =A0 "%-8d" % 1111 can get "1111 =A0 =A0".


Thank you.

Is String#% a requirement or just your first idea?

num =3D 1111
p num.to_s.ljust(8,"0")

#> "11110000"




Harry
 

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

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top