开发者

Division to percentage in Ruby on Rails

If

@prescribed_wod_count = @user.workouts.rx_workouts.count returns 4

and

@user_workout_count = @user.workouts.count returns 26

how come

<%= number_to_percentage(@prescribed_wod_count / @user_workout_count)开发者_如何学C %> returns 0.000% and not 15% ?


It does integer division, before you call number_to_percentage.

You want

<%= number_to_percentage(@prescribed_wod_count.to_f / @user_workout_count) %>

to force it to do floating-point

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜