iphone - 不同的 NSNumberFormatter 行为

标签 iphone cocoa cocoa-touch

考虑这段代码:

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/

相关文章:

ios - SWRevealViewController - RightViewController

swift - 更新自定义 NSWindow 外观

ios - 无法在 Xcode 中使用 PFImageView

ios - 在 Xcode 4.6.3 中安装自定义字体

ios - 使用 Alamofire 和 multipart/form-data

iphone - 在 5.1.1 以下的 ios 版本中的 iphone 应用程序中播放 youtube 视频?

iphone - UILabel 未更新与 IBOutlet 连接

ios - 从 nib 加载 UITableViewCell 的特殊方法

iphone - scrollToRowAtIndexPath :atScrollPosition:animated scrolling too slow

objective-c - 如何创建后台运行的 Cocoa 应用程序?