填充零到价格

3zz*_*zzy 2 php

$price = 10.00;
list($dollars, $cents) = explode('.', $price);
echo $dollars . '.' . $cents;
Run Code Online (Sandbox Code Playgroud)

...除了省略零之外几乎可以工作.10.001010.1010.1

我看到有一个字符串的填充函数,但数字或浮点数是什么?

我该如何解决?

Ema*_*sev 6

你可以使用number_format:

echo number_format($price, 2); // Would print 10.00
Run Code Online (Sandbox Code Playgroud)

您可以为小数点指定分隔符,为数千指定另一个分隔符:

echo number_format(1234.56, 2, ',', ' '); // Would print 1 234,56
Run Code Online (Sandbox Code Playgroud)