• support@answerspoint.com

How can I add commas to numbers in PHP

2031

I would like to know how can I add comma's to numbers. To make my question simple.

I would like to change this:

1210 views

To:

1,210 views

and :

14301

to

14,301

and so on for larger numbers. Is it possible with a php function?

  • PHP

  • asked 8 years ago
  • G John

2Answer


0

from the php manual http://php.net/manual/en/function.number-format.php

I'm assuming you want the english format.

<?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 without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

my 2 cents

  • answered 8 years ago
  • G John

0
$number = 1234.56;

//Vietnam notation(comma for decimal point, dot for thousand separator)

 $number_format_vietnam = number_format($number, 2, ',', '.');

//1.234,56

 

  • answered 8 years ago
  • G John

Your Answer

    Facebook Share        
       
  • asked 8 years ago
  • viewed 2031 times
  • active 8 years ago

Best Rated Questions