我正在尝试累积从数组中获取的NSDecimalNumber值( apptDataArray ,从CoreData存储中获取; aCurrentCharges定义为NSDecimalNumber)。这是我的代码:
NSDecimalNumber *accumulatedFees = 0;
for(int i = 0; i < apptDataArray.count; i++) {
AppointmentInfo *currentAppointment = [apptDataArray objectAtIndex: i];
accumulatedFees = [accumulatedFees decimalNumberByAdding: currentAppointment.aCurrentCharges]; // <---- not accumulating
}
oAccumulatedCharges.text = [NSString stringWithFormat:@"%@",accumulatedFees];
我的问题是标记不累积的行就是这样 - 不累积。我做错了什么?
答案 0 :(得分:3)
变量accumulatedFees
未正确初始化。尝试这样设置:
NSDecimalNumber *accumulatedFees = [NSDecimalNumber zero];