ios:NSLog显示十进制值

时间:2013-04-02 20:54:51

标签: ios nslog nsdecimalnumber

NSNumber *weekNum = [dictionary valueForKey:@"inSeasonFor"];
NSDecimalNumber *newWeekNum = ([weekNum intValue]  *2)/4;
NSLog(@"%", [newWeekNum decimalValue]);

如何将weekNum * 2除以4并保留小数值并打印出来?

1 个答案:

答案 0 :(得分:1)

你的意思是你也想要小数部分,对吧?

NSNumber *weekNum = [dictionary valueForKey:@"inSeasonFor"];
// multiplication by 2 followed by division by 4 is division by 2
NSLog(@"%f", [weekNum intValue] / 2.0f);

//我们也可以使用intfloat来解决。