From: John Joyce Date: 2007-03-30T15:10:48+09:00 Subject: Re: same operation (sort of), different results Yep, you can do integer division but do it last for best results. you can also throw a .to_f method onto everything for your division.. The only way around real division errors is to use large integers, keep track of decimal location in your own custom object for display purposes and thus push the division error way way down to a small, insignificant number. On Mar 30, 2007, at 2:34 PM, Chad Perrin wrote: > On Fri, Mar 30, 2007 at 02:30:33PM +0900, Chad Perrin wrote: >> I'm a little confused by these results. Perhaps someone can tell me >> what I'm assuming incorrectly: >> >> $ irb >> irb(main):001:0> 5 / 9 * ( 100 - 32 ) >> => 0 >> irb(main):002:0> ( 5 / 9 ) * ( 100 - 32 ) >> => 0 >> irb(main):004:0> ( 100 - 32 ) * ( 5 / 9 ) >> => 0 >> irb(main):003:0> ( 100 - 32 ) * 5 / 9 >> => 37 >> >> The last result is the only one that gives me what I actually wanted. >> >> In case you're wondering, yes, that *is* an F-to-C temperature >> conversion. > > Never mind, that was a full-on brain fart. I forgot I was doing > integer > division. Mea culpa. > > -- > CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] > Amazon.com interview candidate: "When C++ is your > hammer, everything starts to look like your thumb." >