如何在結果字符串中每3位數字得到一個簡單的逗號?每三位數字的空格
的代碼如下:
float convertFrom = [[_convertRates objectAtIndex:[picker selectedRowInComponent:0]] floatValue];
float convertTo = [[_convertRates objectAtIndex:[picker selectedRowInComponent:1]] floatValue];
float input = [inputText.text floatValue];
float to = convertTo;
float from = convertFrom;
float convertValue = input;
float relative = to/from;
float result = relative * convertValue;
NSString *convertFromName = [_convertFrom objectAtIndex:[picker selectedRowInComponent:0]];
NSString *convertToName = [_convertFrom objectAtIndex:[picker selectedRowInComponent:1]];
NSString *resultString = [[NSString alloc]initWithFormat:
@" %.4f %@",result, convertToName];
resultLabel.text = resultString;
NSString *formelString = [[NSString alloc]initWithFormat:
@" %.4f %@=", convertValue, convertFromName];
formelLabel.text = formelString;
該代碼使得很多的數字,在文本塊,這是不使用的數據最實用的方式顯示。我如何在這段代碼中實現逗號?
例如,1234567
將是1 234 567
或1'234'567
。
[NSNumberFormatter(https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/Reference/Reference.html) – 2012-10-22 20:40:04