PHP number_format() Function Last Updated : 21 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The number_format() function is an inbuilt function in PHP which is used to format a number with grouped thousands. It returns the formatted number on success otherwise it gives E_WARNING on failure. Syntax: string number_format ( $number, $decimals, $decimalpoint, $sep ) Parameters: This function accepts four parameters as mentioned above and described below: $number: It is required parameter which specified the number to be formatted. If no other parameters are set, the number will be formatted without decimals and with the comma (, ) as the thousands separator. $decimals: It is optional parameter and used to specifies decimals. If this parameter is set, the number will be formatted with a dot (.) as the decimal point. $decimalpoint: It is optional parameter and used to specifies the string to use for the decimal point. $sep: It is optional parameter and used to specifies string to use for thousands separator. If this parameter is given, then all other parameters are required. Return Value: It returns Formatted Number in case success, otherwise it gives E_WARNING in failure. Examples: Input: $number = 100000 Output: 10, 000 Input: $number = 10000 $decimals = 3 $decimalpoints = "." $sep =, Output: 10, 0000.000 Below programs illustrate The number_format() function in PHP: Program 1: php <?php $num1 = "999999.49"; // With out decimal point parameter echo number_format($num1)."\n"; // With decimal Point parameter echo number_format($num1, 3)."\n"; $num2 = "9999999.99"; // With out decimal point parameter // return Round value echo number_format($num2)."\n"; // With decimal Point parameter echo number_format($num2, 3)."\n"; // With All four parameters echo number_format("1000000.99", 3, "#", "GGG"); ?> Output: 999,999 999,999.490 10,000,000 9,999,999.990 1GGG000GGG000#990 Program 2: If pass anything instead of numbers it gives warning. php <?php $num = "GFG"; // With out decimal point parameter echo number_format($num)."\n\n"; // With decimal Point parameter echo number_format($num, 3); ?> Output: PHP Warning: number_format() expects parameter 1 to be float, string given in /home/ac476aaecea758334cb8ed146bcbb8f6.php on line 5 PHP Warning: number_format() expects parameter 1 to be float, string given in /home/ac476aaecea758334cb8ed146bcbb8f6.php on line 8 Program 3: This function does not accept three parameters, only accept 1, 2 or 4 parameters. php <?php $num = 1000000; // passing 3 parameters It gives errors because function // accepting only 1, 2 or 4 parameters echo number_format($num, 3, ", "); ?> Output: PHP Warning: Wrong parameter count for number_format() in /home/e426108b066d9a86366249bf7b626d19.php on line 6 Reference: http://php.net/manual/en/function.number-format.php Comment More infoAdvertise with us R R_Raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP addcslashes() Function The addcslashes() function is a built-in function in PHP. The addcslashes() function is used to add backslashes before some specified characters in a given string. Syntax: string addcslashes($string, $characters) Parameters: This function accepts two parameters as shown in the above syntax and are d 2 min read PHP addslashes() Function The addslashes() function is an inbuilt function in PHP and it returns a string with backslashes in front of predefined characters. It does not take any specified characters in the parameter. The predefined characters are: single quote (')double quote (")backslash (\)NULL Note: The addslashes() func 2 min read PHP bin2hex() Function The bin2hex() function in PHP converts a string to hexadecimal values. The conversion is done byte-wise with the high-nibble first. Note: It is not for converting strings representing binary digits into hexadecimal. Syntax: bin2hex($string) Parameters: This function accepts a single parameter $strin 1 min read PHP chop() Function The chop() in PHP is used to remove white spaces or any other specified characters from the end of a string. Syntax: string chop($string, $character) Parameters: This function accepts two parameters as shown in the above syntax and are described below: $string : It is used to specify the string whic 2 min read PHP chr() Function The chr() function is a built-in function in PHP and is used to convert a ASCII value to a character. It accepts an ASCII value as a parameter and returns a string representing a character from the specified ASCII value. The ASCII value can be specified in decimal, octal, or hex values. Octal values 2 min read PHP chunk_split() Function The chunk_split() function is a built-in function in PHP. The chunk_split() function is used to split a string into smaller chunks of a specific length. Syntax: string chunk_split($string, $length, $end) Parameters: This function accepts three parameters as shown in the above syntax and are describe 2 min read PHP convert_uudecode() Function The convert_uudecode() is a built in function in PHP. This function decode a uuencoded string encoded using convert_uuencode() function. The uudecode() functions makes string into printable form. Syntax: string convert_uudecode(string) Parameters: The uuencoded string which will be decoded. Return T 1 min read PHP convert_uuencode() Function The convert_uuencode() is a built-in function in PHP. The convert_uuencode() function encodes a string using the uuencode algorithm. Uuencode encoding translates all strings (including binary data) into printable characters which makes them safe for network transmissions. Syntax: String convert_uuen 1 min read PHP count_chars() Function The count_chars() is an inbuilt function in PHP and is used to perform several operations related to string like the number of an ASCII character occurs in a string. Syntax : count_chars(string,return_mode); Parameters: The count_chars() function takes two parameters string and return_mode as explai 2 min read PHP crc32() Function The crc32() function helps us to calculate a 32-bit crc or cyclic redundancy checksum polynomial for a string. The function uses the CRC32 algorithm.This function can be used to validate data integrity. However, to ensure that we get the correct string representation from the crc32() function, we ne 2 min read Like