Adding preceding/leading zeros in Integers in rubyOnRails

rjust(n, "0")

For Example

integEr = 5
integEr.to_s.rjust(2, '0')  # => '05'
integEr.to_s.rjust(5, '0')  # => '00005'

next_int = 150
next_int.to_s.rjust(3, '0') # => '150'
next_int.to_s.rjust(5, '0') # => '00150'

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s