请查看这段代码,更具体地说是 hourStep 计算。
int h = [[timeArray objectAtIndex:0] intValue];
int m = [[timeArray objectAtIndex:1] intValue];
int s = [[timeArray objectAtIndex:2] intValue];
int mm = [[timeArray objectAtIndex:3] intValue];
NSLog([NSString stringWithFormat:@"time h:%d, m:%d, s:%d, mm:%d", h, m, s, mm]);
//time h:13, m:7, s:55, mm:105
float hourStep1 = m / 60;
float hourStep2 = h + hourStep1;
float hourStep3 = hourStep2 / 24;
float hourStep4 = hourStep3 * 15;
int hour1 = ceil(hourStep4);
NSLog([NSString stringWithFormat:@"hourStep1: %f, hourStep2: %f, hourStep3: %f, hourStep4: %f result: %d", hourStep1, hourStep2, hourStep3, hourStep4, hour1]);
//hourStep1: 0.000000, hourStep2: 13.000000, hourStep3: 0.541667, hourStep4: 8.125000 result: 9
float hourStep5 = ((h + (m / 60)) / 24) * 15;
NSLog([NSString stringWithFormat:@"hourStep5: %f", hourStep5]);
//hourStep5: 0.000000
我已将计算分解为各个步骤以获得正确答案,但谁能解释为什么 hourStep5 不产生 hourStep4 产生的结果?