Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在目标C中将点转换为逗号数字格式_Ios_Objective C_Nsnumberformatter - Fatal编程技术网

Ios 在目标C中将点转换为逗号数字格式

Ios 在目标C中将点转换为逗号数字格式,ios,objective-c,nsnumberformatter,Ios,Objective C,Nsnumberformatter,我正在尝试将一个数字从美国转换成欧洲格式 投入:34.24 产出:34,24 我尝试使用NSNumberFormatter,但不起作用。有办法吗 NSString *dd = [NSString stringWithFormat:@"%0.2f",amountDouble]; NSNumberFormatter *formatString = [[NSNumberFormatter alloc] init]; [formatString setNumberStyle:NSNumberFormat

我正在尝试将一个数字从美国转换成欧洲格式

投入:34.24 产出:34,24

我尝试使用NSNumberFormatter,但不起作用。有办法吗

NSString *dd = [NSString stringWithFormat:@"%0.2f",amountDouble];
NSNumberFormatter *formatString = [[NSNumberFormatter alloc] init];
[formatString setNumberStyle:NSNumberFormatterCurrencyStyle];
formatString.locale = Locale.currentLocale; //europe locale
NSNumber *reqNumber = [formatString numberFromString:dd]; // returns nil
试着跟随

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc]init]; 
numberFormatter.locale = [NSLocale currentLocale]; 
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; 
numberFormatter.usesGroupingSeparator = YES;

NSString* str = [NSString StringWithFormat:@"%@", 
[numberFormatter stringForObjectValue:dd]];

看可能重复的解决方案并没有完全解决我的问题。硬编码分隔符不能确保基于iPhone区域设置的正确分隔符行为。我只想在europeon语言环境中转换它,否则它不应该转换。输入:34.24美国语言环境输出:34.24和欧洲语言环境输出:34,24所以您只想在语言环境是欧洲语言环境时更改它?在这种情况下,只需将currentlocale测试为european locale,如果为true,则按照另一个问题应用转换