David Garamond <lists / zara.6.isreserved.com> wrote in message news:<40DE9C9F.3030204 / zara.6.isreserved.com>... > I often do this: > > class Float > def round_n(n=0) > raise FloatDomainError unless self.finite? > raise ArgumentError unless n.class == Fixnum && n >= 0 > sprintf("%.#{n}f", self).to_f > end > > def ceil_n(n=0) > raise FloatDomainError unless self.finite? > raise ArgumentError unless n.class == Fixnum && n >= 0 > (self*10**n).ceil.to_f / 10**n > end > > def floor_n(n=0) > raise FloatDomainError unless self.finite? > raise ArgumentError unless n.class == Fixnum && n >= 0 > (self*10**n).floor.to_f / 10**n > end > end > > However I can't help get the feeling that Ruby already has something > like this. Did I indeed miss it? I don't know if this is what you want and I am thinking that there is an easier way but this is pretty simple. puts a=1.1568753256 puts digits=3 puts b=(a)*10**digits puts c=(b).round puts c.to_f/10**digits Just my $0.02 worth, Todd