在 php 中格式化不带小数的数字


Format number without decimal in php

我需要打印这样的数字:123 456 789。(用空格分隔(。我使用number_format,但我不知道如何删除小数。

number_format(123456789, 2, ',', ' ')
//output is 123 456 789,00

当我使用它时:

number_format(123456789)
//output is 123,456,789 - it is not correct

更新:我错了。发生了一些事情,它没有奏效。但这是正确的解决方案。感谢您的帮助。

number_format(123456789, 0, '', ' ') <--- this is correct

只需将零传递给第二个参数,即小数位数:

number_format(123456789, 0, '', ' ')