Preserve trailing zeroes using NumberFormatter in PHP

前端 未结 1 2076
自闭症患者
自闭症患者 2021-01-16 06:02

I\'m working on upgrading a legacy system from PEAR\'s i18nv2 class to PHP\'s built-in INTL library. When I specify a pattern like #,##0.## and run Number

相关标签:
1条回答
  • 2021-01-16 07:02

    http://icu-project.org/apiref/icu4c/classDecimalFormatSymbols.html

    Symbol   Meaning
      0      a digit
      #      a digit, zero shows as absent
    

    So:

    $n = new NumberFormatter('en_CA', NumberFormatter::PATTERN_DECIMAL, '#,##0.00');
    echo $n->format(12345.10000);
    

    Yields:

    12,345.10
    
    0 讨论(0)
提交回复
热议问题