Format numbers The number_format and round
number_format() functions format numbers by grouping thousands.
Syntax: number_format(number,decimals,decimalpoint,separator)
Parameters . The number to format. If no other parameters are set, numbers are formatted without a decimal point and with commas (,) as delimiters.
decimals Optional. Specify the number of decimals. If this parameter is set, numbers are formatted using a period (.) as the decimal point.
decimalpoint Optional. Specifies the string used as the decimal point.
separator Optional. Specifies the string used as the thousands separator. Only the first character of the parameter is used. For example, "xyz" only outputs "x".
Note: If this parameter is set, all other parameters are required.
Tips and Notes
Note: This function supports one, two or four parameters (not three).
<?php echo number_format("1000000"); echo number_format("1000000",2); echo number_format("1000000",2,",","."); ?>
Syntax: round(x,prec)
Parameters . Specifies the number to be rounded.
prec Specifies the number of digits after the decimal point.
Description: Returns the result of rounding x according to the specified precision prec (the number of decimal digits after the decimal point). prec can also be negative or zero (default).
Note: PHP cannot handle strings like "12,300.2" correctly by default.