检查List< float>中的float时的C#精度与包含方法 [英] C# accuracy when checking float in List<float> with Contains method
本文介绍了检查List< float>中的float时的C#精度与包含方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 float
的列表,并想通过 List.Contains()
方法检查它是否已经包含特定值.我知道,对于 float
相等性测试,您通常不能使用 ==
,但是类似 myFloat-value<0.001
.
I have a list of float
s and want to check if it already contains a particular value with the List.Contains()
method. I know that for float
equality tests you often can't use ==
but something like myFloat - value < 0.001
.
我的问题是,是 Contains
方法解决这个问题还是我需要使用一种方法来解决 float
精度错误,以便测试浮点数是否在列表吗?
My question is, does the Contains
method account for this or I do I need to use a method that accounts for float
precision errors for testing if the float is in the list?
推荐答案
查看全文