Convert to numeric

hi, i am new user of ruby on rails
i have a problem in casting a variable in to int , my code is
@EmployeeTenure = Employeepersonaldetail.find_by_sql("select round
(DATEDIFF("date1,date2)/365,0) from table where EmployeeID = 0001)

now if @EmployeeTenure is greater then 5 so make it 5

if (@EmployeeTenure .to_d>5)
@EmployeeTenure=5

but there is an error so help me fixing the problem
thanks

Saboor wrote:

hi, i am new user of ruby on rails
i have a problem in casting a variable in to int , my code is
@EmployeeTenure = Employeepersonaldetail.find_by_sql("select round
(DATEDIFF("date1,date2)/365,0) from table where EmployeeID = 0001)

now if @EmployeeTenure is greater then 5 so make it 5

if (@EmployeeTenure .to_d>5)
@EmployeeTenure=5

but there is an error so help me fixing the problem
thanks

first at all… don’t capitalize a class variable! => @emplozeetenure is
correct

2nd: i don’t remember that there is a to_d method. use to_f, because
float has always double-precision in ruby

3rd: don’t use to_f better use to_i… if there compared number anyway
is a Integer (Fixnum) then better to compare it with a Fixnum.