Strange problem comparing floats in objective-C

后端 未结 7 2365
别跟我提以往
别跟我提以往 2020-11-27 16:25

At some point in an algorithm I need to compare the float value of a property of a class to a float. So I do this:

if (self.scroller.currentValue <= 0.1)          


        
7条回答
  •  时光取名叫无心
    2020-11-27 17:12

    Generally, in any language, you can't really count on equality of float-like types. In your case since it looks like you have more control, it does appear that 0.1 is not float by default. You could probably find that out with sizeof(0.1) (vs. sizeof(self.scroller.currentValue).

提交回复
热议问题