From: Bertram Scharpf Date: 2009-09-26T07:14:56+09:00 Subject: Re: Ruby Noob issue Hi, Am Freitag, 25. Sep 2009, 10:17:53 +0900 schrieb Fred Ige: > Satish Talim wrote: > > Fred, (5/9) is integer division. The decimal part is truncated leaving > > you > > with 0. Use (5.0/9) instead. > > Satish > > Thanks! It works now > I cant believe such a small issue throw me off for so long. Actually, you're not the first one to stumble over the integer/floating point problem. As expressions are evaluated from left to right, the first number coerces the value to be Float. You could also say: (x.to_f - 32) * 5 / 9 Or class Numeric def f2c (to_f - 32) * 5 / 9 end end -32.f2c #=> 0.0 Here's another pitfall about floating point values. Be aware that aren't exact in general. "%20.18f" % 0.3 #=> "0.299999999999999989" Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de