I my Rails application i have a Register Model which contains attendance status of each users.I want to show no of users present on current day (in Percentage).I have found Total no of users Present Today from Register Table and Expected Users from another table.
@totalnoofuserspresent = Register.where(:date => date).sum(:one)
@expectedusers = Workoutplanperday.where(:day => date , :workoutplantype => 1).count
attendance = @totalnoofuserspresent / @expectedusers (ie: 5/10 )
Currently i am getting attendance:0
I want to display it in Percentage ie: 50% or in float ie: 0.50
Thanks in advance….
The problem is, that both variables (@totalnoofuserpresent and @expectedusers) are integers. Ruby assumes you want an integer back, if you you are doing an operation with integers only. So you must convert one of the variables to a float before you do the division.
or easier