2012-08-22 71 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