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.
我需要将 int 和 float 都转换为 float,而不是 string。
我试图将数字转换为带floatval函数的浮点数。
floatval
但floatval(int)回报int。
floatval(int)
int
例如:
floatval(100)返回100
floatval(100)
100
我需要得到100.00
100.00
解决办法是什么?
您可以使用 number_format 函数来格式化所需输出的数字。
$foo = "105.01"; $zoo = "105"; echo number_format((float)$foo, 2, '.', ''); //Output 105.01 echo number_format((float)$zoo, 2, '.', ''); //Output 105.00