Current location - Loan Platform Complete Network - Big data management - How does PHP format numbers?
How does PHP format numbers?
The function of PHP to format numbers is number_format.

I suggest you download a PHP manual or look at the online manual online.

/code/php/

About his usage is as follows:

Syntax: string number _ format (float number, int [decimals], string [dec _ point], string [methods _ sep]);

Return value: string

Function Type: Mathematical Operation

Content description

This function is used to format the number of floating-point parameters. If the parameter decimals is not added, the returned string only needs the integer part, and only after this parameter is added can it be returned according to the decimal places specified by the parameter. The parameter dec_point indicates the decimal point representation method, and the default value is ".". If you need to convert to other decimal points, you can change it in this parameter. The parameter thousands _sep is the separator of every three bits of the integer part, and the default value is ",". The most special feature of this function is the number of parameters, at least one, which is the string to be formatted; There can also be two or four parameters, but not three. Raise money? Note that the number after the specified decimal point is discarded directly without rounding.

Use case

& lt?

$ short _ pi = " 3. 14 159 ";

$my_pi = number_format($short_pi,2);

echo $my_pi。 ”\ n”; // 3. 14

$ foo = 8500 17.902 1;

$new_foo = number_format($foo,3," ", " ");

echo $new_foo。 ”\ n”; // 850 0 17.902

& gt