NSDecimalNumber保存有较少数量的零,我在文本字段6000,00 $例如进入,但在tableview中出现$ 6.00NSDecimalNumber
请帮我解决这个问题
下面是我的代码:
@property (strong, nonatomic) NSNumberFormatter *currencyFormatter;
@synthesize currencyFormatter;
- (void)viewDidLoad
{
[super viewDidLoad];
nameTextField.text = editGift.nameOfGift;
currencyFormatter = [[NSNumberFormatter alloc]init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
priceTextField.text = [currencyFormatter stringFromNumber:[editGift priceOfGift]];
}
- (IBAction)saveChanges:(id)sender {
editGift.nameOfGift = nameTextField.text;
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSDecimalNumber *priceAmount = [NSDecimalNumber decimalNumberWithString:priceTextField.text];
editGift.priceOfGift = priceAmount;
AppDelegate *myApp = (AppDelegate *) [[UIApplication sharedApplication]delegate];
[myApp saveContext];
[self.delegate editGiftViewControllerDidSave:self];
}
显示中的tableView:
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc]init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
cell.giftCostLabel.text = [currencyFormatter stringFromNumber:[gift priceOfGift]];
添加代码 - 货币格式化以及如何显示数值。 – Sulthan
请你可以检查我的代码我添加了货币格式化程序,以及我如何在我的tableview中显示值。谢谢 – Astakhoff
您已经将数字格式化为货币格式因此,无需在表格视图中再次进行转换。你有机会尝试我的代码吗? –