Я не могу добиться округления поплавка.
Все эти вызовы возвращают мне 3,5999999, а не 3,6 для theoTimeoutTrick и theoTimeout.
Как я могу получить это значение 3,6 в NSString AND float vars?
#define minTimeout 1.0
#define defaultNbRetry 5
float secondsWaitedForAnswer = 20.0;
float minDelayBetween2Retry = 0.5;
int theoNbRetries = defaultNbRetry;
float theoTimeout = 0.0;
while (theoTimeout < minTimeout && theoNbRetries > 0) {
theoTimeout = (secondsWaitedForAnswer - (theoNbRetries-1)*minDelayBetween2Retry) / theoNbRetries;
theoNbRetries--;
}
float theoTimeoutTrick = [[NSString stringWithFormat:@"%.1f", theoTimeout] floatValue];
theoTimeout = roundf(theoTimeout * 10)/10.0;
NSLog(@"%f", 3.6);
, вы обнаружите, что он действительно печатает3.60000
- person   schedule 25.07.2011