gpt4 book ai didi

iphone - 不同的 NSNumberFormatter 行为

转载 作者:行者123 更新时间:2023-12-03 17:26:58 24 4
gpt4 key购买 nike

考虑这段代码:

NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.numberStyle = NSNumberFormatterCurrencyStyle;

NSLocale *l = [[NSLocale alloc] initWithLocaleIdentifier:@"it_IT"];
nf.locale = l;
[l release];
nf.decimalSeparator = @",";
nf.currencySymbol = @"US$";
[nf setLenient:YES];
NSString *s = @"US$ 0,05";
double d = [[nf numberFromString:s] doubleValue];
NSLog(@"%.2f",d);`

如果我在普通的基于 Cocoa 控制台的应用程序 (10.6 sdk) 中执行此操作,我会在调试控制台中得到输出“0.05”。

但是,如果我在 iPhone 环境 (OS 3.1.3) 中执行此操作,我会在调试控制台中得到“0.00”输出。我使用 NSNumberFormatter 是否做错了什么?或者这是两个平台之间的差异?

最佳答案

NSString *s = @"US$ 0,05";

如果删除空格会怎样?

关于iphone - 不同的 NSNumberFormatter 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2410244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com