如何在 ios 6 中转换5112225.14
为。5,112,225.14
我试过这个:
NSNumber *numberObj = [NSNumber numberWithFloat:[[string stringByReplacingOccurrencesOfString:@"," withString:@""] floatValue]];
也试过
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle]; // this line is important!
NSString *formatted = [formatter stringFromNumber:[NSNumber numberWithInteger:2000000.879]];
但我得到5,112,225第一个和2,000,000 没有任何小数。我如何保留小数点和逗号分隔值。提前致谢,圣诞快乐。