From: Florian Frank Date: 2005-12-22T09:43:12+09:00 Subject: Re: sprintf Michael 'entropie' Trommer wrote: >irb(main):004:0> sprintf("%2s", "lalaa") >=> "lalaa" >irb(main):005:0> sprintf("%2i", 1212) >=> "1212" > >ruby 1.8.3 (2005-09-21) [i686-linux] > >What s my mistake? > > You didn't use a precision: sprintf("%10.2s", "lalaa") # => " la" This creates a size 10 string, left padded with spaces, and copies only two characters from the argument. sprintf("%10.2f", 1212.123) # => " 1212.12" This creates a size 10 string, left padded with spaces, and displays the floating point number with two decimal places. -- Florian Frank