PHP 需要加上两位小数和一个逗号

PHP Need to impose two decimals and a comma

我有一些 php 看起来像这样的脚本

<?php echo "$" . round(( floatval( preg_replace( "/[^-0-9\.]/", "", $row['display_price'] ) ) * 1.03 ), 2); ?>

它的作用是采用这样的值:$13,116.89 ea

并提出 price/number 高出 3%。即:13510.4 美元

我需要对这个值施加一个逗号和千分号,并且无论返回值如何,总是施加两位小数。我也可以将这个新计算的值作为字符串显示,这不是问题。

感谢所有帮助。

http://php.net/manual/en/function.number-format.php

$input = 13116.89;

echo '$' . number_format($input, 2);

// output: ,116.89
$OriginalValue = 13116.89;
$IncreasedValue *= 1.03;
$FormattedNumber = "$" . number_format($IncreasedValue, 2);

这是关于 number_format 的 PHP 文档:

http://php.net/manual/en/function.number-format.php