How to format a number with thousands separators
Short answer
number_format() takes the number, the number of decimal places, the decimal separator and the thousands separator:
<?php
echo number_format(1234567.891, 2, ',', ' ');Output:
1 234 567,89Without the fraction
With zero decimal places the number is rounded to a whole:
<?php
echo number_format(1234567.891, 0, '', ' ');Output:
1 234 568The English format
By default thousands are separated by a comma and the fraction by a dot:
<?php
echo number_format(1234567.891, 2);Output:
1,234,567.89