This function requires you to log in. Please enter your login details
View Subcategory
Zero pad a number
Given the number 42, pad it to 8 characters like 00000042
ruby
42.to_s.rjust(8,"0")
"%08d" % 42
Right Space pad a number
Given the number 1024 right pad it to 6 characters
"1024 "
ruby
num = 1024
s = 1024.to_s
puts s + (6-s.length) * " "
s = 1024.to_s
puts s + (6-s.length) * " "
Format a decimal number
Format the number 7/8 as a decimal with 2 places: 0.88
ruby
(7.0/8.0*100).round/100.0
Left Space pad a number
Given the number 73 left pad it to 10 characters
" 73"
ruby
73.to_s.rjust(10)
