Come potrei arrotondare un galleggiante all'intero più vicino in Objective-C:Objective-C Float A completare
Esempio:
float f = 45.698f;
int rounded = _______;
NSLog(@"the rounded float is %i",rounded);
deve stampare "il galleggiante arrotondato è 46"
Questo produrrà solo un arrotondamento _downward_. Per ottenere <.5 rounds down e> = .5 rounds up: [NSString stringWithFormat: @ "% i", (int) round (f)] – mpemburn
effettivamente no. Questo produrrà l'arrotondamento più vicino. –
Questo non gestisce correttamente i numeri negativi. – AndrewCr