这只是一个指示性示例,说明如何执行此操作。您应该研究此代码并根据您的情况重新调整它。试试看:
@autoreleasepool
{
// Here I create the formatter and I set the format. You do this faster with setFormat: .
NSNumberFormatter* formatter=[[NSNumberFormatter alloc]init];
formatter.numberStyle= NSNumberFormatterCurrencyStyle;
formatter.maximumIntegerDigits=6;
formatter.maximumFractionDigits=2;
formatter.currencySymbol= @"$";
formatter.currencyDecimalSeparator= @".";
formatter.currencyGroupingSeparator= @",";
formatter.positivePrefix=@"";
NSArray* numbers= @[ @1 ,@2 ,@3 ,@4, @5, @6, @7, @8 ];
// These are the inserted numbers, you should change the code in a way that
// every number is taken in input from the text field.
float number=0.0f;
for(NSUInteger i=0;i<8;i++)
{
// It just simulates what happens if the user types the numbers in the array.
number= [numbers[i] floatValue] * 1.0e-2 + number*10;
NSLog(@"%@",[formatter stringFromNumber: @(number)]);
}
}