如何在结果字符串中每 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
。