iOS NSNumber isEqualToNumber

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 基础

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 线程

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> OpenGL ES

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> GPUImage

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> AVFoundation

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> CocoaPods


一.NSNumber isEqualToNumber 简介

/*

 If:
    a < b   then return NO. The left operand is smaller than the right operand.
    a > b   then return NO. The left operand is greater than the right operand.
    a == b  then return YES. The operands are equal.
*/

- (BOOL)isEqualToNumber:(NSNumber *)number;

二.NSNumber isEqualToNumber 实战

/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:iOS NSNumber isEqualToNumber
//@Time:2021/09/22 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/

NSNumber *number1 = [NSNumber numberWithFloat:10.0];
NSNumber *number2 = [NSNumber numberWithFloat:20.0];
NSNumber *number3 = [NSNumber numberWithFloat:30.0];
NSNumber *number4 = [NSNumber numberWithFloat:30.0];
    
NSLog(@"number1 = %@ number2 = %@ number3 = %@",number1,number2,number3);
    
//number1 < number2
NSLog(@"[number1 isEqualToNumber:number2]:%d",[number1 compare:number2]);
    
//number2 > number1
NSLog(@"[number2 isEqualToNumber:number1]:%d",[number2 compare:number1]);
    
//number3 = number4
NSLog(@"[number3 isEqualToNumber:number4]:%d",[number3 compare:number4]);

/*
number1 = 10 number2 = 20 number3 = 30
[number1 isEqualToNumber:number2]:0
[number2 isEqualToNumber:number1]:0
[number3 isEqualToNumber:number4]:1
*/

三.猜你喜欢


未经允许不得转载:猿说编程 » iOS NSNumber isEqualToNumber
喜欢(0) 打赏

评论抢沙发

评论前必须登录!

不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!!

开始学习

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏