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.
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.
On Wed, Dec 1, 2010 at 5:29 PM, jun yu [email protected] wrote:
Is String#% a requirement or just your first idea?
num = 1111
p num.to_s.ljust(8,“0”)
#> “11110000”
Harry
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs