PHP string number_format() function

PHP string 'number_format()' is in-built PHP function. It is used to format a number with grouped thousands. It supports one, two or three parameters (not three).

Syntax:

ParameterDescriptionRequired/Optional
numberThe number being formatted.Required
decimalSet the number of decimal point.Optional
decimalpointSets the separator for the decimal point.Optional
separatorSet the thousand separatorOptional

Example 1

Output:

Your number is:199.9
By using 'number_format()' function :200

Example 2

Output:

Your number is:199.9
By using 'number_format()' function :199.90

Example 3

Output:

Your number is:1000000
By using 'number_format()' function :1,000,000

Example 4

Output:

Your number is:1000000
By using 'number_format()' function :1,000,000.00

Next TopicPHP String




Latest Courses