0

可能重复:
php中的简单正则表达式,格式化十进制数

如何在php中将x格式的数字转换为x.xx格式?示例:我有一个数字 5。需要转换为 5.00

4

6 回答 6

3
$n = 5;
$n = number_format($n, 2, '.', '');
于 2012-05-23T08:59:52.023 回答
2

你应该尝试number_format()

$your_number = 5;

echo number_format($your_number, 2); // displays 5.00

手动的

于 2012-05-23T08:59:21.490 回答
1

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

于 2012-05-23T08:59:17.933 回答
1
number_format('your digit', 2 or 1, '.', '');
于 2012-05-23T08:59:26.203 回答
0
 $number = 125

 $no = number_format($number, 2, '.', '');


 output = 125.00
于 2012-05-23T09:24:07.783 回答
0
$x = 5;
$x = sprintf('%.2f', $x);
echo $x;
于 2012-05-23T09:29:49.760 回答