Format a number with grouped thousands in PHP

Description

The following code shows how to format a number with grouped thousands.

Example


<?php/*from   ww  w.  java  2  s  .co m*/

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
echo $english_format_number;

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
echo $nombre_format_francais;

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
echo $english_format_number;
// 1234.57

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone