objective c - What's the correct way to accumulate NSDecimalNumber values? -
i trying accumulate nsdecimalnumber values obtained array (apptdataarray, obtained coredata store; acurrentcharges defined nsdecimalnumber). code:
nsdecimalnumber *accumulatedfees = 0; for(int = 0; < apptdataarray.count; i++) { appointmentinfo *currentappointment = [apptdataarray objectatindex: i]; accumulatedfees = [accumulatedfees decimalnumberbyadding: currentappointment.acurrentcharges]; // <---- not accumulating } oaccumulatedcharges.text = [nsstring stringwithformat:@"%@",accumulatedfees];
my problem line marked not accumulating doing -- not accumulating. doing wrong?
the variable accumulatedfees
not being initialized correctly. try setting way:
nsdecimalnumber *accumulatedfees = [nsdecimalnumber zero];
Comments
Post a Comment