【问题标题】:Add comma to a whole number with PHP用PHP将逗号添加到整数
【发布时间】:2018-02-27 10:43:01
【问题描述】:

如何用 PHP 给整数加逗号?

示例: $数字 = 1000 $output_i_want = 10,00

示例 2: $数字 = 10000 $output_i_want = 100,00

【问题讨论】:

标签: php numbers format decimal comma


【解决方案1】:

您将数字除以 100,然后以 2 位小数显示结果。

只需使用 number_format:

$number="1000"; 
echo number_format(($number/100), 2, ',', ' ');

【讨论】:

    【解决方案2】:

    PHP function number_format()

    PHP Arithmetic Operators

    number_format( 1000 / 100 , 2, ',', ' ');
    number_format( 10000 / 100 , 2, ',', ' ');
    

    【讨论】:

      猜你喜欢
      • 2021-03-13
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2011-04-22
      相关资源
      最近更新 更多