Current Location: Home> Function Categories> number_format

number_format

Format a number in a thousand separator
Name:number_format
Category:String
Programming Language:php
One-line Description:Format numbers in thousands of groups.

Definition and usage

number_format() function formats numbers by grouping thousands of bits.

Note: This function supports one, two, or four parameters (not three).

Example

Example 1

Format numbers:

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

Try it yourself

Example 2

You want to return a price: One parameter will round the number (formatted with no decimal places), and two parameters give the result you want:

 <?php
$num = 4999.9 ;
$formattedNum = number_format ( $num ) . "<br>" ;
echo $formattedNum ;
$formattedNum = number_format ( $num , 2 ) ;
echo $formattedNum ;
?>

Try it yourself

Similar Functions
  • Tag split string strtok

    strtok

    Tagsplitstring
  • Returns information about the characters used in the string - counts the number of times each byte value (0..255) occurs in a string count_chars

    count_chars

    Returnsinformationab
  • Convert binary data to hexadecimal representation bin2hex

    bin2hex

    Convertbinarydatatoh
  • Use another string to fill a string to a length str_pad

    str_pad

    Useanotherstringtofi
  • Escape characters in a string using backslashes in C style addcslashes

    addcslashes

    Escapecharactersinas
  • Alias ​​of rtrim chop

    chop

    Alias​​ofrtrim
  • Generate single-byte strings from numbers chr

    chr

    Generatesingle-bytes
  • Convert string to lowercase strtolower

    strtolower

    Convertstringtolower
Popular Articles