ios - Subtracting Currency - NSNumber -
im dealing currency values need subtract each other. read nsnumber dealing currency, unable subtract 2 nsnumbers. there better way dealing currencys or missing small?
nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init]; [numberformatter setnumberstyle: nsnumberformattercurrencystyle]; nsnumber* number = [numberformatter numberfromstring:bdict[@"booking_deposit"]]; if (!number) { [numberformatter setnumberstyle: nsnumberformatterdecimalstyle]; number = [numberformatter numberfromstring:bdict[@"booking_deposit"]]; } nsnumber* number2 = [numberformatter numberfromstring:bdict[@"booking_total"]]; if (!number2) { [numberformatter setnumberstyle: nsnumberformatterdecimalstyle]; number2 = [numberformatter numberfromstring:bdict[@"booking_total"]]; } nslog(@"result %@",number2 - number);//warning here
and heres warning:
arithmetic on pointer interface 'nsnumber', not constant size architecture , platform
you can't subtract objects, that's why error.
you use nsdecimalnumber
instead of nsnumber
, have api decimalnumberbysubtracting:
.
alternatively, use double
.
the main point use data type allows level of precision you're interested in, , relates number of , type of calculations you're going make.
nsnumberformatter
offer generatesdecimalnumbers
(it used have bug, not sure if still does, worth investigation).
Comments
Post a Comment