NSTimeInterval
具有亚毫秒精度。如果日期相隔一天零一毫秒,您将收取第25个积分。
将代码更改为整数除法应该可以解决以下问题:
// You do not need sub-second resolution here, because you divide by
// the number of seconds in the hour anyway
NSInteger ti = [endDate timeIntervalSinceDate:startDate];
NSInteger costValue = (ti+3599)/3600;
// At this point, the cost is ready. You do not need a special formatter for it.