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

How can I divide weekNum*2 by 4 and keep the decimal value and print it?

有帮助吗?

解决方案

You mean you want the fractional part as well, right?

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

//we can also use intfloat to resolve.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top