Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top