Hi,
I want to format an integer as hours and minutes.
Of course it’s easy to write this myself, but let’s respect DRY!
Is there a method I can use so that integers are converted to strings of
2 digits?
So:
2 --> 02
11 --> 11
4 --> 04
thanks!
Hi,
I want to format an integer as hours and minutes.
Of course it’s easy to write this myself, but let’s respect DRY!
Is there a method I can use so that integers are converted to strings of
2 digits?
So:
2 --> 02
11 --> 11
4 --> 04
thanks!
Yep, you can use sprintf:
sprintf(“%0.2d”, 4)
=> “04”
–
Thiago J.
acts_as_solr => http://acts-as-solr.rubyforge.org
Sitealizer Web Stats => http://sitealizer.rubyforge.org
On Mar 28, 3:50 pm, Brij N. [email protected]
4 --> 04
sprintf("%02d", 4) => 04
-philip
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