PHP number_format Function

PHP Tutorial > String Functions > number_format Function

The number_format function in PHP is used to set the format of a numerical output. The syntax of the number_format function is:

number_format (number, [number_of_decimals], [decimal_character], [thousand_separator_character])

where the optional parameter number_of_decimals is how many digits to display after the decimal point. The optional parameter decimal_character specifies the character to use as a decimal ('.' is the default). The optional parameter thousad_separator_character is the character to use as the thousand separator (',' is the default).

Let's take a look at the examples below:

Example 1

print number_format(1.532, 1);



Example 2

print number_format(5432.105, 3, ',', '.');



Note this is the number format that's used in Europe.

Next: PHP print Function

Copyright © 2017  All Rights Reserved.  Privacy Policy   About   Contact