【问题标题】:Format number with dot instead of comma as thousand separator用点而不是逗号作为千位分隔符的格式数字
【发布时间】:2017-04-27 14:59:01
【问题描述】:

如果我使用number_format 来格式化这样的数字:

$price = 1500;
echo number_format($price);

然后我得到这样的输出:1,500

如何使千位分隔符成为点而不是逗号(即,将1.500 作为我的输出)?

【问题讨论】:

    标签: php


    【解决方案1】:

    number_format 的第三个和第四个参数分别控制用于小数点和千位分隔符的字符。所以你可以这样做:

    number_format(
        1500,
        0, // number of decimal places
        ',', // character to use as decimal point
        '.' // character to use as thousands separator
    )
    

    并获得"1.500" 作为您的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 2014-11-27
      • 2010-12-21
      相关资源
      最近更新 更多