On 28.10.2009 19:21, Matthew K. Williams wrote: > On Thu, 29 Oct 2009, Aldric Giacomoni wrote: > >> Matthew K. Williams wrote: >>>> irb(main):016:0> 123.6 - 123.0 >>>> => 0.599999999999994 >>>> >>>> That's a little strange.. Isn't it? >>> No, it's not. Welcome to the wonderfully confusing world of floating >>> point math... >> Oh, thanks. Can I have some pop-corn and an introductory pamphlet before >> I bash my head against the wall? :) > > Pamphlet -> http://en.wikipedia.org/wiki/IEEE_754-2008 > > Popcorn, well, it's kinda hard to transmit over the wire. ;-) Easy to do with a modern email client - just needs support for POP3 and a working firewall (for the heat). :-) > As a rule of thumb, if you really care about the decimals, either use > BigDecimal or integers (and keep track of where the decimal should be -- > this is common for $$$$). Unfortunately, this is not limited to ruby, > either -- C, Java, and a host of other languages all are subject. Absolutely: this is a common issue in *all* programming languages which are not systems for symbolic math (like Mathematica) because they do not work with real numbers but just rational numbers. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/