gpt4 book ai didi

php - 在 PHP 中删除尾随零直到小数点后两位

转载 作者:行者123 更新时间:2023-12-04 17:57:04 25 4
gpt4 key购买 nike

我试过转换到 floatnumber_format但 float 将始终舍入为 2,并且 number_format 固定在您指定的小数位数上。

那么我怎样才能像下面的转换一样做到这一点

11.2200 -> 11.22
11.2000 -> 11.20
11.2340 -> 11.234

最佳答案

$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"

这可能会有所帮助,您可以使用 sprintf由 PHP 提供。

关于php - 在 PHP 中删除尾随零直到小数点后两位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39591195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com