【问题标题】:NSnumberFormatter working on simulator but not on deviceNSnumberFormatter 在模拟器上工作但不在设备上
【发布时间】:2012-09-13 12:39:51
【问题描述】:

我的应用中有一个价格字段。我使用了 NSNumberFormatter,我正在使用核心数据存储和检索值。它在模拟器上运行良好,但设备上没有显示任何内容。

我还显示了在模拟器上运行良好但在设备上运行良好的本地货币值。我对货币使用了以下代码:

NSLocale *theLocale = [NSLocale currentLocale];
NSString *a = [theLocale objectForKey:NSLocaleCurrencySymbol];

【问题讨论】:

  • 检查设备Locale和模拟器Locale是否相同
  • 不,但我在模拟器中更改了语言环境并检查它并且它有效。
  • 模拟器在美国,我手机的地区是印度。
  • 变量theLocale 在您的设备上运行时是否包含印度语言环境,还是返回nil[[NSLocale preferredLanguages] objectAtIndex:0]; 怎么样(即使根据首选语言设置返回当前语言,而不是根据您应该用于货币符号的区域设置的当前语言环境,也值得检查这是否有效或返回 nil太)
  • 它返回的卢比符号和首选语言在模拟器上返回 en

标签: iphone objective-c ios xcode nsnumberformatter


【解决方案1】:

对于印度数字系统

    NSNumberFormatter *frm=[[NSNumberFormatter alloc] init];
[frm setNumberStyle:NSNumberFormatterDecimalStyle];

    [frm setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"] autorelease]];
[frm setCurrencySymbol:@""];

NSString *formattedAmt=[frm stringFromNumber:[NSNumber numberWithDouble:tmpAmt]];

将 LocaleIdentifier 更改为 en_US 表示百万

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-19
    • 2023-03-23
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多