It would be nice to have an equivalent of R\'s signif function in Ruby.
For example:
>> (11.11).signif(1) 10 >> (22.22).signif(2) 22 >
Here's an implementation that doesn't use strings or other libraries.
class Float def signif(digits) return 0 if self.zero? self.round(-(Math.log10(self).ceil - digits)) end end