简体   繁体   English

十进制到双精度

[英]decimal to double

I have something like this..... 我有这样的东西.....

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;
}

but the class is... 但是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; }
}

the problem is... In the class Report_TeachersPosition , I have all decimal values from database . 问题是...在class Report_TeachersPosition ,我具有database所有decimal值。 And I want them to be in double . 我希望他们能double So i change it into double and save it. 所以我将其更改为double并保存。 but when I open it again, Its back to decimal .. I dont know why.. Can somebody help???? 但是当我再次打开它时,它返回到decimal ..我不知道为什么..有人可以帮忙吗?

If your database is storing the values as decimal then everytime you fetch them from the database they are always going to come back as decimal . 如果您的数据库将值存储为decimal则每次从数据库中获取它们时,它们总是会以decimal返回。

The more important question is why do you want the values as double ? 更为重要的问题是, 为什么要让值double If it's for display purposes then I would recommend you use appropriate formatting. 如果是出于显示目的,那么我建议您使用适当的格式。 Bare in mind, you will lose accuracy when you convert from decimal to double . 切记,从decimal转换为double时,您将失去准确性。

Is public partial class Report_TeachersPosition a database generated class? 公共局部类Report_TeachersPosition是数据库生成的类吗? (I suppose yes). (我想是的)。 You must change type of database table column and then regenerate model class 您必须更改数据库表列的类型,然后重新生成模型类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM