Example 1 — Format Thousands and Decimals
Format the same number three different ways.
<?php
$n = 1234567.891;
echo number_format($n), PHP_EOL;
echo number_format($n, 2), PHP_EOL;
echo number_format($n, 2, ",", "."), PHP_EOL; How It Works
- No decimals given. The default is 0, so the number rounds up.
- Ask for 2 decimals. You see .89 after rounding.
- Swap separators. Comma for decimals and dot for thousands.
- Pick the style. Use the one your users expect.

