From: George Ogata Date: 2006-12-04T11:36:41+09:00 Subject: Re: number format On 12/4/06, Li Chen wrote: > Hi all, > > I have a number, for example, 1.123456789. What is the Ruby way to > change it into whatever number of floating points such as 1.12, > 1.123,1.1234568 or 1.12345679. > > Thanks, > > Li > > -- > Posted via http://www.ruby-forum.com/. > > It might be better to leave the precision alone until you print it, in which case, you can print it with #sprintf or String#% or similar: irb(main):001:0> '%.2f' % 1.23456789 => "1.23" irb(main):002:0> '%.5f' % 1.23456789 => "1.23457"