如果
@prescribed_wod_count = @user.workouts.rx_workouts.count
返回4
和
@user_workout_count = @user.workouts.count
返回26
怎么来
<%= number_to_percentage(@prescribed_wod_count / @user_workout_count) %>
返回0.000%
而不是15%?
答案 0 :(得分:18)
在调用number_to_percentage之前进行整数除法。
你想要
<%= number_to_percentage(@prescribed_wod_count.to_f / @user_workout_count) %>
强制它做浮点