本文主要是介绍OC-NSNumber,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//NSNumber(封装类型的时候是封装有效的数据类型)NSNumber *number = [NSNumber numberWithInt:5];NSLog(@"%@",number);NSNumber *number1 = [NSNumber numberWithFloat:5];NSLog(@"%@",number1);NSNumber *number2 = [NSNumber numberWithDouble:5.0f];NSLog(@"%@",number2);NSNumber *number3 = [NSNumber numberWithFloat:5.3];NSLog(@"%@",number3);
输出结果:
2014-12-17 20:52:15.266 OC-lwy-3(OC数据类型)[1651:534402] 5
2014-12-17 20:52:15.267 OC-lwy-3(OC数据类型)[1651:534402] 5
2014-12-17 20:52:15.267 OC-lwy-3(OC数据类型)[1651:534402] 5
2014-12-17 20:52:15.267 OC-lwy-3(OC数据类型)[1651:534402] 5.3
Program ended with exit code: 0
NSNumberFormatter
NSNumber *number = [NSNumber numberWithInt:123456];//创建NSNumberFormatter对象NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];//设定格式[formatter setNumberStyle:NSNumberFormatterSpellOutStyle];//连接fomattter对象和number对象NSString *string = [formatter stringFromNumber:number];NSLog(@"string = %@",string);//NSNumberFormatterSpellOutStyle :十二万三千四百五十六
输出结果:
2014-12-17 20:54:07.766 OC-lwy-3(OC数据类型)[1667:549215] string = 十二万三千四百五十六
Program ended with exit code: 0
这篇关于OC-NSNumber的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!