8
@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%?
@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%?
在調用number_to_percentage之前,它進行整數除法。
你想
<%= number_to_percentage(@prescribed_wod_count.to_f/@user_workout_count) %>
,迫使它執行浮點
完美的感謝。 – bgadoci 2010-11-30 07:12:06