Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 PHP 中的浮点值末尾删除不必要的零,例如:
3.0 --> 3 12.56300 --> 12.563 etc.
您可以只使用 (double) 或 (float) 而不使用 (string)
echo (float)$input;
number_format($number, number of digits);
例如
echo number_format(2.222222, 2); //2.22
我发现这样做的一种简单方法如下:
$output = (double) (string) $input;