NSNumber对象用法:

点击(此处)折叠或打开


1. void test(void)
2. {
3. NSNumber *myNumber, *floatNumber,*intNumber;
4. NSInteger myInt;
5.
6. intNumber = [NSNumber numberWithInt:10];
7. myInt = [intNumber integerValue];
8. NSLog(@"%li",myInt);
9.
10. myNumber = [NSNumber numberWithLong:0xabced];
11. NSLog(@"%lx",[myNumber longValue]);
12.
13. floatNumber = [NSNumber numberWithFloat:9];
14. NSLog(@"%g",[floatNumber floatValue]);
15.
16. if ([intNumber isEqualToNumber:floatNumber] == YES) {
17. NSLog(@"num are equal");
18. } else {
19. NSLog(@"num are not equal");
20. }
21. if ([intNumber compare:floatNumber] == NSOrderedAscending) {
22. NSLog(@"first number less than second");
23. }
24. }