How do I format numbers to have only two decimal places?

In PHP, try number_format:

$n = 1234.5678;

// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57

Leave a Comment