From: "Derrick B." Date: 2012-12-24T03:24:00+09:00 Subject: Re: simple division: -9 / 5 = -2 what? 7stud -- wrote in post #1089926: > Derrick B. wrote in post #1089918: >> $ irb >> irb(main):001:0> -9 / 5 >> => -2 >> irb(main):002:0> -9.to_f / 5.to_f >> => -1.8 >> irb(main):003:0> (-9.to_f / 5.to_f).to_i >> => -1 >> >> If I want to assign the integer quotient of the above example, do I >> really need to go from float to integer? >> > > No: > > p -9.divmod 5 > > --output:-- > [-2, 1] a = -9 b = 5 p a.divmod b )[0] --output:-- -2 But I want a "correct" answer, which is not -2. Hence: p ( a.to_f / b.to_f ).to_i --output:-- -1 ...which is ugly, or better (maybe?): p (a.fdiv b).to_i --output:-- -1 -- Posted via http://www.ruby-forum.com/.