PHP has two decimal places, and php has two decimal places.
Recently, I am making statistics on this part. There are many data sources related to numbers,
Three functions are used to retain the last N digits after decimal places. Next, we will briefly introduce the three functions:
1. number_format
Echo number_format ("5000000 "). "<br>"; echo number_format ("5000000", 2 ). "<br>"; echo number_format ("5000000", 2 ,",",". ");
This function is mainly used to format data in sub-groups.
Output result
5,000,000
5,000,000.00
5.000.000,00
2. sprintf
$ Num = 123; $ data = sprintf ("%. 2f", $ num); echo $ data;
The result is:
123.00
3. round
$ Num1 = 123.1267 $ data1 = round ($ num1, 2); $ num2 = 123 $ data2 = round ($ num2, 2 ); echo $ data1. "<br>" echo $ data2
The result is:
123.13
123
If the number of decimal points is less than two, it will not be automatically filled.