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

如何將weekNum * 2除以4並保留小數值並打印出來?ios:NSLog顯示十進制值

回答

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來解決。