【发布时间】:2021-08-21 19:48:08
【问题描述】:
我正在尝试使用这个简单的 php 表达式计算 BMI:
$bmi = $weight/pow($height, 2);
体重:70 身高:170 它输出:0.0024221453287197
但正确的结果必须是:24.22,如何去掉所有这些小数和零,谢谢。
【问题讨论】:
-
这能回答你的问题吗? PHP number format without comma
我正在尝试使用这个简单的 php 表达式计算 BMI:
$bmi = $weight/pow($height, 2);
体重:70 身高:170 它输出:0.0024221453287197
但正确的结果必须是:24.22,如何去掉所有这些小数和零,谢谢。
【问题讨论】:
这是怎么回事..
$num = 0.0024221453287197;
// move the decimal right 4 places.
$num = $num * 10000;
// format the number
echo number_format($num, 2);
在http://sandbox.onlinephpfunctions.com/code/b95dd43a426b5d55bf1fddd9faf7b13116908192 测试。
【讨论】:
【讨论】: