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

如何将 weekNum*2 除以 4 并保留十进制值并打印它?

4

1 回答 1

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来解析。

于 2013-04-02T20:58:03.163 回答