1
votes

I'm trying to format $123,123 USA currency in an app displaying properties on a map. The number show $(null) should show the #

Incompatible integer to pointer conversion initializing 'NSInteger *' (aka 'long *') with an expression of type 'NSInteger' (aka 'long')

Implicit conversion from enumeration type 'enum CFNumberFormatterStyle' to different enumeration type 'NSNumberFormatterStyle' (aka 'enum NSNumberFormatterStyle')

cell.imgViewPropertyType.image = [UIImage imageNamed:@"for_sale"];
NSInteger *intPrice = [theProperty.priceSale integerValue];
NSNumber *tempPrice = [NSNumber numberWithInteger:intPrice];
NSString *price = [NSNumberFormatter localizedStringFromNumber:tempPrice numberStyle:kCFNumberFormatterCurrencyStyle];
1

1 Answers

0
votes

Try with this. Note that intPrice is not a pointer and hence you need to declare as NSInteger intPrice instead of NSInteger *intPrice. That is the reason for the error which you are getting.

cell.imgViewPropertyType.image = [UIImage imageNamed:@"for_sale"];
NSInteger intPrice = [theProperty.priceSale integerValue];
NSNumber *tempPrice = [NSNumber numberWithInteger:intPrice];

As rmaddy pointed below, you can also use below line.

NSNumber *tempPrice = @(intPrice);

Regarding second error about CFNumberFormatterStyle, localizedStringFromNumber accepts NSNumberFormatterStyle and not type CFNumberFormatterStyle. You are trying to pass wrong type of style there. Try with NSNumberFormatterCurrencyStyle.

NSString *price = [NSNumberFormatter localizedStringFromNumber:tempPrice numberStyle:NSNumberFormatterCurrencyStyle];