我正在使用以下代码将文本字段中输入的数字转换为格式化以显示美元货币。所以它显示了 $ 符号,并且每 3 位数字(从右起)添加 a 。我在文本字段中设置格式化文本。
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *pureNumbers = [[textField.text componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];
//Convert entered text to NSNumber
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:pureNumbers];
NSString *currencyString = [currencyFormatter internationalCurrencySymbol];
NSString *format = [currencyFormatter positiveFormat];
format = [format stringByReplacingOccurrencesOfString:@"*" withString:currencyString];
// ¤ is a placeholder for the currency symbol
[currencyFormatter setPositiveFormat:format];
NSString *currencyString1 = [currencyFormatter stringFromNumber:myNumber];
NSLog(@"Text is %@",currencyString1);
textField.text = currencyString1;
}
现在我怎样才能找回删除数字格式化程序输入的数字?示例:我在文本字段中输入了 5000。它在文本字段中格式化为 5,000 美元。我想从用户输入的原始值的文本字段中取回“5000”。