class Float def truncate(sd=2) scale=(10**sd).to_f (self * scale).to_i / scale end end a=0.255 a.truncate(2) #-> 0.25