Replace string with float : String format « String « Ruby






Replace string with float


'To 2 decimal places: %.2f' % Math::PI      # => "To 2 decimal places: 3.14"
'Zero-padded: %.5d' % Math::PI              # => "Zero-padded: 00003"

 








Related examples in the same category

1.use % for format printing
2.Substituting Variables Into an Existing String
3.Changing the Case of a String
4.Center, left justify and right justify string