PHP显示更多的十进制数字


PHP Show more decimal numbers

当我在输入中写入数字时,我想显示这样的200,00。

就像我写200,数字自动变为200,00

我该怎么做?

<?
Value 1 <input type="text" name="value1">
Value 2 <input type="text" name="value2">
?>
<?
$total = $value1 + $value2;
?>

$total在的末尾必须有,00个数字

尝试number_format函数

$total = "1279";
echo number_format($total, 2, ',', '.'); // 1.279,00

语法

number_format(number, decimal, decimal seperator, thousand seperator)

使用number_format在站点上回显变量。

请参见此处:http://php.net/manual/en/function.number-format.php

number_format($total, 2, ',', '');

尝试使用名为number_format 的函数

echo number_format($total,2);
number_format( $total, 2, ',', '' );