Format Number with Commas

Format a number with thousand separators for better readability.

Code

Utilities
$decimals = floor($num) == $num ? 0 : strlen(explode('.', (string)$num)[1] ?? '');
return number_format($num, $decimals);

Parameters

The number to format.

Server

More PHP Snippets