How to properly compare decimal values in C#?

后端 未结 4 747
忘掉有多难
忘掉有多难 2020-12-16 09:23

I come from a background in C++, and I know that you cannot accurately compare floats for equality. For C#, I simply assumed the same policy applies to decimal values, or an

4条回答
  •  醉话见心
    2020-12-16 09:47

    I think this will solve your problem.

    Basically there is a decimal.compare method.

    EDIT: This may be the better method:

    Decimal.Equals

    EDIT2: If you can compare directly as suggested above, that may be more efficient. I will leave this as it may be of interest.

提交回复
热议问题