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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.