Ruby on Rails中的百分比

bga*_*oci 9 ruby math ruby-on-rails division

如果

@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%?

And*_*ess 18

在调用number_to_percentage之前,它会执行整数除法.

你要

<%= number_to_percentage(@prescribed_wod_count.to_f / @user_workout_count) %>
Run Code Online (Sandbox Code Playgroud)

强迫它做浮点