C#datatable 增加表達式列和處理表達式列小數位數

dt.Columns.Add("Elec_Product_Value", typeof(double), " IIF(ProductYield is not null and ProductYield>0 and Elec_Value is not null, Convert(Elec_Value/ProductYield*10000,'System.Int64')/10000, null)");
        dt.Columns.Add("Water_Product_Value", typeof(double), " IIF(ProductYield is not null and ProductYield>0 and Water_Value is not null, Convert(Water_Value/ProductYield*10000,'System.Int64')/10000, null)");
        dt.Columns.Add("Steam_Product_Value", typeof(double), " IIF(ProductYield is not null and ProductYield>0 and Steam_Value is not null, Convert(Steam_Value/ProductYield*10000,'System.Int64')/10000, null)");
        dt.Columns.Add("CA_Product_Value", typeof(double), " IIF(ProductYield is not null and ProductYield>0 and CA_Value is not null, Convert(CA_Value/ProductYield*10000,'System.Int64')/10000, null)");
        dt.Columns.Add("WasteWater_Product_Value", typeof(double), " IIF(ProductYield is not null and ProductYield>0 and WasteWater_Value is not null, Convert(WasteWater_Value/ProductYield*10000,'System.Int64')/10000, null)");

其中:表達式中可以使用IIF(條件,表達式1,表達式2)三元運算符,使用Convert(Elec_Value/ProductYield*10000,'System.Int64')/10000進行保留4位小數位數

 

參考:https://www.jb51.net/article/86254.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章