2012-08-22 69 views
0

我有这样的事情.....小数翻番

foreach (var pupilAvg in pupilsAvgs) { 
    Report_TeachersPosition teacher = new Report_TeachersPosition(); 
    teacher.ORG_ID = pupilAvg.ORG_ID; 
    teacher.Yearcode = pupilAvg.YearCode; 
    teacher.Teacher_K5 = pupilAvg.PupilsAvg_K5/ratio.ClassKto5; 
    teacher.Teacher_6to8 = pupilAvg.PupilsAvg_6to8/ratio.Class6to8; 
    teacher.Teacher_9to12 = pupilAvg.PupilsAvg_9to12/ratio.Class9to12; 
    teacher.Teacher_EPSFTE = teacher.Teacher_K5 + teacher.Teacher_6to8 
          + teacher.Teacher_9to12; 
    teacher.Teacher_Adjusted_EPSSalary = teacher.Teacher_SAUEPSMatrix 
             * teacher.Teacher_Ratio; 
    teacher.Teacher_ElementarySalary = teacher.Teacher_Adjusted_EPSSalary 
             * entities.Report_Attending_Pupils_Avg.ToList() 
             .Where(x => x.ORG_ID == pupilAvg.ORG_ID 
             && x.YearCode.Equals("" + yearCode)) 
             .FirstOrDefault().PupilsAvg_K8_Percentage; 
    teacher.Teacher_SecondarySalary = teacher.Teacher_Adjusted_EPSSalary 
             * entities.Report_Attending_Pupils_Avg.ToList() 
             .Where(x => x.ORG_ID == pupilAvg.ORG_ID 
             && x.YearCode.Equals("" + yearCode)) 
             .FirstOrDefault().PupilsAvg_9to12_Percentage; 
} 

class是...

public partial class Report_TeachersPosition { 
     public int ORG_ID { get; set; } 
     public Nullable<int> Yearcode { get; set; } 
     public Nullable<decimal> Teacher_K5 { get; set; } 
     public Nullable<decimal> Teacher_6to8 { get; set; } 
     public Nullable<decimal> Teacher_K8 { get; set; } 
     public Nullable<decimal> Teacher_9to12 { get; set; } 
     public Nullable<decimal> Teacher_EPSFTE { get; set; } 
     public Nullable<decimal> Teacher_ActualFTE { get; set; } 
     public Nullable<decimal> Teacher_Ratio { get; set; } 
     public Nullable<decimal> Teacher_TotalSalary { get; set; } 
     public Nullable<decimal> Teacher_ElementarySalary { get; set; } 
     public Nullable<decimal> Teacher_SecondarySalary { get; set; } 
     public Nullable<decimal> Teacher_SAUEPSMatrix { get; set; } 
     public Nullable<decimal> Teacher_Adjusted_EPSSalary { get; set; } 
} 

问题是...在class Report_TeachersPosition,我都decimal来自database的值。我希望他们在double。所以我把它改成double并保存。但当我再次打开它,它回到decimal ..我不知道为什么..有人可以帮助吗?

回答

0

是公共分部类Report_TeachersPosition数据库生成的类? (我想是的)。您必须更改数据库表格列的类型,然后重新生成模型类

+0

ya ..它的数据库生成的类..但我不能让它在数据库中的双倍... –

+0

那么,为什么你想要在代码中改变它?它的目的是什么? –

1

如果您的数据库正在将值存储为decimal,那么每次从数据库中获取它们时,它们总是会返回为decimal

更重要的问题是为什么你想要的值为double?如果是出于显示目的,那么我会建议你使用适当的格式。请记住,当您从decimal转换为double时,您将失去准确性。

+0

我不能在视觉工作室中使用小数... –

+1

你是什么意思“不能使用”? –

+0

@TuHazlo“*不能在视觉工作室中使用小数*”呃? – James