php - 如何将数字格式化为只有两位小数?

标签 php mysql

我希望实数是 12.92,而不是 12.9241。可以这样吗?

最佳答案

在 PHP 中,尝试 number_format :

$n = 1234.5678;

// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57

关于php - 如何将数字格式化为只有两位小数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1992406/

相关文章:

php - 使用 ?> 还是 php?>

php - “计算”符合特定条件的记录数并显示数字(使用 PHP 和 MySQL)

php - 如何从我的存储过程中获取第二个 SELECT?

连续日期的MySQL实现

php - Laravel Eloquent 查询关系

PHP RegEx 防止重复字符

javascript - 面对转义反斜杠不断堆积的情况

php - Symfony2 中使用 Twig 的动态主题

sql - 有没有一种方法可以让我在测试其中一个结果时使用 CASE 而不是运行它两次?

php - Apache 使用过多的 CPU