float类型得分计算最终得分时精度损失

This commit is contained in:
sw 2015-05-29 11:26:39 +08:00
parent 23a457af9e
commit 91b17ea91f
1 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,7 @@
class StudentWorkController < ApplicationController
layout "base_courses"
include StudentWorkHelper
require 'bigdecimal'
before_filter :find_homework, :only => [:new, :index, :create]
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
@ -150,7 +151,10 @@ class StudentWorkController < ApplicationController
if @work.student_score.nil?
@work.final_score = @work.teaching_asistant_score
else
@work.final_score = format("%.2f",@work.teaching_asistant_score * @homework.homework_detail_manual.ta_proportion + @work.student_score * (1 - @homework.homework_detail_manual.ta_proportion))
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}")
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}"))
final_score = final_ta_score + final_s_score
@work.final_score = format("%.2f",final_score.to_f)
end
end
when 3 #学生评分 学生评分显示平均分
@ -159,7 +163,10 @@ class StudentWorkController < ApplicationController
if @work.teaching_asistant_score.nil?
@work.final_score = @work.student_score
else
@work.final_score = format("%.2f",@work.teaching_asistant_score * @homework.homework_detail_manual.ta_proportion + @work.student_score * (1 - @homework.homework_detail_manual.ta_proportion))
final_ta_score = BigDecimal.new("#{@work.teaching_asistant_score}") * BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}")
final_s_score = BigDecimal.new("#{@work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{@homework.homework_detail_manual.ta_proportion}"))
final_score = final_ta_score + final_s_score
@work.final_score = format("%.2f",final_score.to_f)
end
end
end