self.numberFormatter = [[NSNumberFormatter alloc] init]; [self.numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [self.numberFormatter setCurrencySymbol:@""]; [self.numberFormatter setLocale:[NSLocale currentLocale]];
//In DataManager sharedClass .h
- (void)setupCapital:(float)Capital;
- (float)readCapital;
(NSString*)formatCapital:(NSNumber *)Capital;
// In DataManager sharedClass .m
@property (assign, nonatomic) float theCapital;
- (NSString *) formatCapital:(NSNumber *)Capital {
return [self.numberFormatter stringFromNumber:Capital];
}
- (void)formatCapital:(float)Capital {
self.theCapital = Capital;
}
- (float) readCapital {
return self.theCapital;
}
// write the number
float numberDecimal = [[DataManager sharedClass] readCapital];
self.labelCapital.text = [[DataManager sharedClass] formatCapital:[NSNumber numberWithFloat:numberDecimal]];
123456,89 を挿入すると、labelCapital に値 123.456,89 が正しく含まれる理由
1234567,89 を挿入すると、代わりに labelCapital 1.234.567,88 になります。
123456789,89 を挿入すると、代わりに labelCapital 123.456.792,00 になります。
ヒントはありますか?