gpt4 book ai didi

php - 将零填充到价格

转载 作者:行者123 更新时间:2023-12-03 23:24:29 26 4
gpt4 key购买 nike

$price = 10.00;
list($dollars, $cents) = explode('.', $price);
echo $dollars . '.' . $cents;

... 几乎可以工作,只是省略了零。 10.00变成 1010.10变成 10.1
我看到有一个用于字符串的填充函数,但对于数字或浮点数有什么用?

我该如何解决?

最佳答案

您可以使用 number_format :

echo number_format($price, 2); // Would print 10.00

您可以为小数点指定一个分隔符,为千位指定另一个分隔符:
echo number_format(1234.56, 2, ',', ' '); // Would print 1 234,56

关于php - 将零填充到价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14786928/

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