PHP显示更多小数

时间:2013-09-05 08:54:40

标签: php input numbers decimal

我希望在输入时将这些数字显示为200,00。

就像我写200并自动将数字更改为200,00

我该怎么做?

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

$total最后必须有00个数字

4 个答案:

答案 0 :(得分:1)

尝试number_format功能

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

语法

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

答案 1 :(得分:1)

使用number_format回显您网站上的变量。

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

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

答案 2 :(得分:0)

尝试使用名为number_format

的函数
echo number_format($total,2);

答案 3 :(得分:0)

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