How can I format this number correctly using PHP?



PHP Snippet 1:

<?php
$a = "159.95";
$b = "12345";
$a_number = str_replace(",", ".", $a);
$b_number = str_replace(",", ".", $b);

echo number_format($a_number,2,",","."), "\n";
echo number_format($b_number,2,",","."), "\n";
?>

PHP Snippet 2:

<?php
echo number_format("1000000")."<br>";
echo number_format("1000000",2)."<br>";
echo number_format("1000000",2,",",".");
?>

PHP Snippet 3:

1,000,000
1,000,000.00
1.000.000,00

PHP Snippet 4:

$n = 123.45;

$multiple = 10;

$result = (ceil($n)%$multiple === 0) ? ceil($n) : round(($n+$multiple/2)/$multiple)*$multiple;

echo $result;

PHP Snippet 5:

$display_result = number_format($result,2);