//
// main.m
// NSNumber
//
// Created by 裴烨烽 on 14-3-28.
// Copyright (c) 2014年 裴烨烽. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// 声明三个NSNumber指针类型的变量
NSNumber *integerNumber;
NSNumber *myNumber;
NSNumber *floatNumber;
// NSInteger 是long的别名,不属于对象
NSInteger myInteger;
// 把整数存入NSNumber中,再取出整数并打印输出
integerNumber=[NSNumber numberWithInteger:100];
myInteger=[integerNumber integerValue];
NSLog(@"%li",(long)myInteger);
//把16进制的整数存入NSNumber中,再取出整数打印并输出
myNumber=[NSNumber numberWithLong:0xabcdef];
NSLog(@"%lx",[myNumber longValue]);
myNumber =[NSNumber numberWithChar:‘X‘];
NSLog(@"%c",[myNumber charValue]);
floatNumber=[NSNumber numberWithFloat:100.00];
NSLog(@"%g",[floatNumber floatValue]);
myNumber=[NSNumber numberWithDouble:12345e+15];
NSLog(@"%lg",[myNumber doubleValue]);
NSLog(@"%li",[myNumber integerValue]);
//错误的对等判断
if(integerNumber==floatNumber)
{
NSLog(@"相等");
}
else{
NSLog(@"不相等");
}
//大小比较
if([integerNumber compare:myNumber]==NSOrderedAscending)
{
NSLog(@"第一个数小于第二个数");
}
}
return 0;
}
原文:http://www.cnblogs.com/madeininfi/p/3630605.html