Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top