From: MaggotChild Date: 2009-12-02T13:30:14+09:00 Subject: Re: Float Arithmetic: Return A Fixnum When Float == Fixnum On Dec 1, 12:24 pm, "Glen F. Pankow" wrote: >> MaggotChild wrote: >> >> j == j.to_i ? j.to_i : j >> => 2 >> Is there a "better" way? > > Ugly, but what the hey: > > j = 2.0 > sprintf('%g', j) --> "2" > > j = 2.50000001 > sprintf('%g', j) --> "2.5" > > Works on integers, too: > > j = 2 > sprintf('%g', j) --> "2" Ah, I knew it -a better way. And to think, it was with a printf format... All those years of C down the toilet