php中的2个十进制数字?

时间:2010-08-01 09:14:35

标签: php

例如:
(a)123 /(b)1000 =(c)0,123
echo c必须是0,12

怎么办呢?

3 个答案:

答案 0 :(得分:6)

使用round()sprintf()number_format()

示例:

<?php
$res = 123/1000;
printf('%.2f', $res);
echo round($res, 2);
echo number_format($res, 2);
?>

答案 1 :(得分:0)

使用number_format http://php.net/number_format

答案 2 :(得分:0)

使用sprintf()可以做到这一点。

相关问题