dttvb115151 2013-05-02 09:36
浏览 75
已采纳

NumberFormatter :: formatCurrency返回带有“fr_FR.UTF-8”的NaN

The following issue occurs with apache on Ubuntu 13.04(not sure about other OS's) I tried with fr_LU too but to no avail

Doesn't work -returns NaN

setlocale(LC_MONETARY, 'fr_FR.UTF-8');
$currency_formatter = NumberFormatter::create(setlocale(LC_MONETARY, "0"), NumberFormatter::CURRENCY);
$currency_formatter->formatCurrency(100, 'USD');

What am I missing here?

Result for locale -a on my machine is as follows:

  C
    C.UTF-8
    de_AT.utf8
    de_BE.utf8
    de_CH.utf8
    de_DE.utf8
    de_LI.utf8
    de_LU.utf8
    en_AG
    en_AG.utf8
    en_AU.utf8
    en_BW.utf8
    en_CA.utf8
    en_DK.utf8
    en_GB.utf8
    en_HK.utf8
    en_IE.utf8
    en_IN
    en_IN.utf8
    en_NG
    en_NG.utf8
    en_NZ.utf8
    en_PH.utf8
    en_SG.utf8
    en_US
    en_US.iso88591
    en_US.utf8
    en_ZA.utf8
    en_ZM
    en_ZM.utf8
    en_ZW.utf8
    fr_BE.utf8
    fr_CA.utf8
    fr_CH.utf8
    fr_FR
    fr_FR.iso88591
    fr_FR.utf8
    fr_LU.utf8
    ja_JP.utf8
    POSIX
    zh_CN.utf8
    zh_SG.utf8
  • 写回答

1条回答 默认 最新

  • dtbhp60824 2013-05-16 19:32
    关注

    Followed a comment at https://bugs.php.net/bug.php?id=54538 which goes as follows: "I have observed a workaround. Setting LC_MESSAGES does not affect NumberFormatter and is sufficient for gettext translations at the same time."

    I commented It is a workaround and it worked for me. This is how my code looks after the change

    putenv('LC_MESSAGES='.$locale);
    setlocale(LC_MESSAGES, $locale);
    setlocale(LC_TIME, $locale);
    //Don't set LC_NUMERIC and LC_MONETARY as these may interfere with number formatter and cause to return NaN(https://bugs.php.net/bug.php?id=54538)
    //setlocale(LC_NUMERIC, $locale);
    //setlocale(LC_MONETARY, $locale);
    
    $currency_formatter = NumberFormatter::create(setlocale(LC_MESSAGES, "0"), NumberFormatter::CURRENCY);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛