c# - LINQ查询,忽略带有某些小数点的结果

标签 c# linq double where-clause decimal-point

我需要在 C# 中对大型数据库执行 LINQ 查询。我需要在查询中使用的列之一是双列。我需要忽略此列中小数点后 4 位以上的结果。数据库无法更改,因为其他程序需要使用它并使用我不想要的东西。然后将结果添加到列表中以备后用。我认为这会奏效。

where fun.Units != '*.?????*'

但是它会返回字 rune 字中字符过多的错误。 到目前为止,整个查询看起来像这样

var clientQuery1 = from cli in main1.Clients
                   from pol in main1.Policies
                   from fun in main1.FundHoldings
                   from uni in main1.UnitPrices
                   where cli.AccountNumber == accNum
                   && pol.ClientRef == cli.ClientRef
                   && fun.FKeyRef == pol.PolicyRef
                   && uni.UnitPriceRef == fun.UnitPriceRef
                   && fun.Units != '*.?????*'
                   select uni.UnitName;

最佳答案

能否请您尝试以下查询并告诉我。

var clientQuery1 = from cli in main1.Clients
                   from pol in main1.Policies
                   from fun in main1.FundHoldings
                   from uni in main1.UnitPrices
                   where cli.AccountNumber == accNum
                   && pol.ClientRef == cli.ClientRef
                   && fun.FKeyRef == pol.PolicyRef
                   && uni.UnitPriceRef == fun.UnitPriceRef
                   && fun.Units == Math.Round(Convert.ToDouble(fun.Units),4)
                   select uni.UnitName;

关于c# - LINQ查询,忽略带有某些小数点的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255239/

相关文章:

c# - 如何编码 C# 结构数组?

c# 字节和位转换 - 这可以做得更好吗?

c# - 可空类型存储在内存中的什么位置?

c# - 查询表时Azure表过滤器和Linq有什么区别?

java - int 和 double 除以 double java

c++ - 如何在一个区间内循环遍历 double 的每个值?

c# - 提高从 MethodCallExpression 获取 MethodInfo 的性能

c# - 多列表与单列表 Linq 查询比较

c# - 为什么对外部数据源的更改没有反射(reflect)出来,而对内部数据源却显示出来了?

java - 如何在 if 语句中保留我的值?