Addition of Double values inconsistent

后端 未结 7 2074
渐次进展
渐次进展 2021-01-20 01:13

I came across following issue while developing some engineering rule value engine using eval(...) implementation.

    Dim first As Double = 1.1
    Dim secon         


        
7条回答
  •  青春惊慌失措
    2021-01-20 01:25

    that's how the double number work in PC. The best way to compare them is to use such a construction

    if (Math.Abs(second - first) <= 1E-9)
     Console.WriteLine("Matched")
    

    instead if 1E-9 you can use another number, that would represent the possible error in comparison.

提交回复
热议问题