ruby计算完成率

task_complete = ((task_forms_w.to_f / task_forms_num.to_f)*100).round(2).to_s << "%" #完成率

方式2

#自动计算时间跨度  /3600
    time_rang=(powerCutRecord.end_time - powerCutRecord.begin_time).to_i
    powerCutRecord.time_range=sprintf("%.1f",time_rang/3600.0)  #保留一位小数点 
原文地址:https://www.cnblogs.com/lmg-jie/p/7773189.html