From: Josh Cheek Date: 2011-07-18T22:03:04+09:00 Subject: Re: Ruby output formater --0016e6475ed688daae04a8579ef8 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jul 18, 2011 at 7:52 AM, raju sathliya 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)` --0016e6475ed688daae04a8579ef8--