陈斌彬的技术博客

Stay foolish,stay hungry

NSNumber 转 Double

NSNumber *numObj = [NSNumber numberWithInt: 2];
NSLog(@"numObj=%@",numObj); 
NSInteger myInteger = [numObj integerValue];

NSLog(@"myInteger=%d",myInteger); 
int a = [numObj intValue];
NSLog(@"a=%d",a);

//浮点数值使用CGFloat,NSDecimalNumber对象进行处理:
NSDecimalNumber *myDecimalObj = [[NSDecimalNumber alloc] initWithString:@"23.30"]; 
NSLog(@"myDecimalObj doubleValue=%6.3f",[myDecimalObj doubleValue]); 

CGFloat myCGFloatValue = 43.4; 
NSDecimalNumber *myOtherDecimalObj = [[NSDecimalNumber alloc] initWithFloat:myCGFloatValue]; 
NSLog(@"myOtherDecimalObj doubleValue=%6.5f",[myOtherDecimalObj doubleValue]);