How dangerous is it to compare floating point values?

前端 未结 11 810
囚心锁ツ
囚心锁ツ 2020-11-21 06:44

I know UIKit uses CGFloat because of the resolution independent coordinate system.

But every time I want to check if for example fram

11条回答
  •  太阳男子
    2020-11-21 07:07

    You can use such code for compare float with zero:

    if ((int)(theView.frame.origin.x * 100) == 0) {
        // do important operation
    }
    

    This will compare with 0.1 accuracy, that enough for CGFloat in this case.

提交回复
热议问题