一.NSNumber创建

        NSNumber *intNumber = [[NSNumber alloc]initWithInt:1];
        NSNumber *charNumber = [[NSNumber alloc]initWithChar:'c'];
        NSNumber *floatNumber = [[NSNumber alloc]initWithFloat:5.0f];
        NSNumber *doubleNumber = [[NSNumber alloc]initWithDouble:6.7];

二.NSNumber操作

首先我们创建两个number

        NSNumber *intNumber1 = [[NSNumber alloc]initWithInt:1];
        NSNumber *intNumber2 = [[NSNumber alloc]initWithInt:2];

1.两个number是否相等

        BOOL ret = [intNumber1 isEqualToNumber:intNumber2];
        NSLog(@"ret is %zd",ret);

  输出结果:

2016-06-27 23:00:00.176 OcTest[506:50872] ret is 0
Program ended with exit code: 0

2.两个number进行比较

        NSComparisonResult result = [intNumber1 compare: intNumber2];
        if(result == NSOrderedAscending){
            NSLog(@"intNumber1 < intNumber2");
        }else if(result == NSOrderedDescending){
            NSLog(@"intNumber1 < intNumber2");
        }else if(result == NSOrderedSame){
            NSLog(@"intNumber1 = intNumber2");
        }

  输出函数:

2016-06-27 23:03:31.441 OcTest[516:59026] intNumber1 < intNumber2
Program ended with exit code: 0

  

 

posted on 2016-06-25 17:42  chengkaihua  阅读(124)  评论(0编辑  收藏  举报