From: Paul Lutus Date: 2006-12-04T17:00:08+09:00 Subject: Re: number format Daniel Finnie wrote: > You can use the number.round method, but this doesn't take a number of > decimal places. > > To round 1.234 to 1.23 use this code: > x = 1.234 > x = x * 100 # -> 123.4 > x = x.round -> 123 > x = x / 100.0 => 1.23 > > At least, that's the best method I can find from the Ruby docs... This is not a good idea. Because the number being manipulated is binary but the display is decimal, the multiplication and division steps will fail on some numbers -- many, in fact -- and those numbers will print more decimal places than was intended. It's better to retain the full binary resolution of a number internally, and only show certain decimal places while printing a number -- don't try to truncate the number itself. -- Paul Lutus http://www.arachnoid.com