How dangerous is it to compare floating point values?

前端 未结 11 829
囚心锁ツ
囚心锁ツ 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:06

    -(BOOL)isFloatEqual:(CGFloat)firstValue secondValue:(CGFloat)secondValue{
    
    BOOL isEqual = NO;
    
    NSNumber *firstValueNumber = [NSNumber numberWithDouble:firstValue];
    NSNumber *secondValueNumber = [NSNumber numberWithDouble:secondValue];
    
    isEqual = [firstValueNumber isEqualToNumber:secondValueNumber];
    
    return isEqual;
    

    }

提交回复
热议问题