How can I add commas to numbers in PHP?

convert Numbers to Roman Numbers with PHP
Extract PHP numbers from strings

This solution will teach us how to add commas to numbers.

solution 1.

Assuming the english format solution

<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation with a decimal point and without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

solution 2.

The following code may be helpful.

$number = 1234.56;

echo number_format($number, 2, '.', ',');

//1,234.56

Output
convert Numbers to Roman Numbers with PHP
Extract PHP numbers from strings
en English
X
Scroll to Top