CKTIS / PHP
number_format()
Format a numeric value as text with grouping and half-up rounding.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
number_format(float $num, int $decimals = 0, ?string $decimal_separator = ".", ?string $thousands_separator = ","): stringFormat a numeric value as text with grouping and half-up rounding. Choose separators explicitly for presentation, including an empty grouping separator for none. Since PHP 8.3 a negative decimals count rounds digits before the decimal point. The result is a formatted string, not a quantity for arithmetic.
Signature
number_format(float $num, int $decimals = 0, ?string $decimal_separator = ".", ?string $thousands_separator = ","): string
Example output
["1 234,50","1300","1.3"]
Examples
<?php
echo json_encode([number_format(1234.5,2,","," "),number_format(1299,-2,".",""),number_format(1.25,1)]);
Result
["1 234,50","1300","1.3"]