且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数字的小数点前加零

更新时间:2023-02-21 16:22:34

您想要的功能是

The function you want is number_format

echo number_format(0.96, 2);

或者,如果缺少它,您可以检查并添加它.

Alternatively you can just check for and prepend it if it is missing.

if ($num[0] == '.')
  $num = '0' . $num;

尽管这不会处理负数,但您需要为此编写更多的逻辑.

This wont handle negative numbers though, you would need to write a little more logic for that.