Thomas Jollans <nospam / jollans.com> writes:

> while learning ruby i wanted to program a simple fahrenheit to celsius
> converter. for that i need 9/5 to be 1,8 (and not 1). how do i do that in
> ruby?

As with many other languages, dividing an integer by an integer produces an
integer. Make at least one of them a floating point number and the returned
value will be floating point.

irb(main):001:0> 9.0 / 5
=> 1.8
irb(main):002:0> 9 / 5.0
=> 1.8

If your two values are stored in variables, then you can call "to_f" to
force them to be floating point, like this:

irb(main):003:0> x = 9
=> 9
irb(main):004:0> y = 5
=> 5
irb(main):005:0> x / y
=> 1
irb(main):006:0> x.to_f / y
=> 1.8
irb(main):007:0> x / y.to_f
=> 1.8
irb(main):008:0> x.to_f / y.to_f
=> 1.8

Jim
-- 
Jim Menard, jimm / io.com, http://www.io.com/~jimm/
"Even anarchists have an agenda." -- Keith Beal