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

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