diff --git a/content/php/concepts/string-functions/terms/number-format/number-format.md b/content/php/concepts/string-functions/terms/number-format/number-format.md new file mode 100644 index 00000000000..ba1ceaa21d4 --- /dev/null +++ b/content/php/concepts/string-functions/terms/number-format/number-format.md @@ -0,0 +1,53 @@ +--- +Title: 'number_format()' +Description: 'Returns a given value formatted with grouped thousands.' +Subjects: + - 'Computer Science' + - 'Web Design' +Tags: + - 'Strings' + - 'Functions' +CatalogContent: + - 'learn-php' + - 'paths/computer-science' +--- + +The **`number_format()`** function takes a given number and formats it with grouped thousands. If a decimal is given, the number will be rounded up. + +## Syntax + +```pseudo +number_format($number, $decimals, $decimal_point, $separator); +``` + +- `$number`: The number to format. +- `$decimals`: Optional parameter that sets the number of digits after the decimal point. If not given, the number returned will be a whole number. +- `$decimal_point`: Optional parameter that specifies the decimal separator and should be given as a string. +- `$separator`: Optional parameter that specifies the thousands separator and should be given as a string. + +## Example + +This example uses the `number_format()` function to format a whole number using `","` as a decimal separator and `"x"` as a thousands separator. + +```php + +``` + +This will result in the following output: + +```shell +1x000x000,00 +``` + +## Codebyte Example + +The following codebyte example can be run and calls the `number_format()` method two times. The second call uses the optional `$decimals`, `$decimal_point`, and `$separator` parameters. + +```codebyte/php + +```