From: soxinbox Date: 2005-10-03T13:11:47+09:00 Subject: Re: Truncating Floats for more enjoyment and greater efficiency: (s=2.33333.to_s + "00").slice(0,s.index(".")+3) "James Edward Gray II" wrote in message news:AF6D1EBB-D94C-40C7-913E-CE6137D99FFA@grayproductions.net... > On Oct 1, 2005, at 4:31 AM, Kero wrote: > >>> Probably cause you can do it in one line: >>> >>> ('%.2f' % 0.255).to_f >>> >> >> That's rounding, not truncating. > > Okay, how about: > > 0.255.to_s.sub(/(\.\d{2})\d+/, "\\1").to_f > > James Edward Gray II > >