On Mon, Jul 18, 2011 at 7:52 AM, raju sathliya <raju.sathliya / gmail.com>wrote:

> Hello,
> I need to display number in 3 digit instead by defaul digit.
> e.g.
> val = 5
> puts #{val}
>
> will give me answer as 5
> but need to display output in 3 digit only like 005.
>
> Can anyone suggest me solution for this.
>
> Thanks,
> raju
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
You want printf http://ruby-doc.org/core/classes/IO.html#M000894 There is a
breakdown of everything it can do on sprintf
http://ruby-doc.org/core/classes/Kernel.html#M001432

In this particular case, it would be `printf('%03d', val)`