1、将数字转化为字符串的快捷方式
2、请彻底抛弃float类型,使用CGFloat或double,float不够精确.
BOOL b1 = YES; BOOL b2 = NO; NSInteger t1 = 100000; int t2 = 200000; float t3 = 300000.02; CGFloat t33 = 300000.02; double t4 = 400000.0000003; NSNumber *num1 = @(123); NSNumber *num2 = @(123.00005); NSLog(@"BOOL b1:%@",[@(b1) stringValue]); //BOOL b1:1 NSLog(@"BOOL b2:%@",[@(b2) stringValue]); // BOOL b2:0 NSLog(@"NSInteger t1:%@",[@(t1) stringValue]); //NSInteger t1:100000 NSLog(@"int t2:%@",[@(t2) stringValue]); //int t2:200000 NSLog(@"float t3:%@",[@(t3) stringValue]); //float t3:300000 ##失真 NSLog(@"float t3:%f",t3); //float t3:300000.031250 ##失真 NSLog(@"float t3:%.2f",t3); //float t3:300000.03 ##失真 NSLog(@"float t33:%@",[@(t33) stringValue]); //float t33:300000.02 NSLog(@"float t33:%f",t33); //float t33:300000.020000 NSLog(@"double t4:%@",[@(t4) stringValue]); //double t4:400000.0000003 NSLog(@"NSNumber *num1:%@",[num1 stringValue]); //NSNumber *num1:123 NSLog(@"NSNumber *num2:%@",[num2 stringValue]); //NSNumber *num2:123.00005
原文:http://www.cnblogs.com/ygm900/p/4780900.html