From: Jeff Vogt Date: 2009-02-14T03:05:09+09:00 Subject: Re: Bug in converting float to int? Gary Wright wrote: > Ruby floating point values are stored in binary format. > 10.12 (decimal) can not be represented exactly in binary: > > >> sprintf("%0.50f", 10.12) > => "10.11999999999999921840299066388979554176330566406250" Clifford Heath wrote: > Avoid using floating point. Seriously. Some might advice you to round: > (a*100).round => 1012, but that's *unreliable*, even with some quite > small number of digits. > > Store cents as an integer, or use BigDecimal. Thanks everyone, quite interesting info there. It looks like I will be doing my dollars to cents math a little differently. Clifford, can you elaborate on why round is unreliable? -- Posted via http://www.ruby-forum.com/.