This article mainly introduces the use of PHP sprintf function, need friends can refer to the followingControl floating-point number printing format floating point of print and format control is a common function of sprintf, floating-point numbers using the format character "%f" control, the default retention of 6 digits after the decimal points, such as: The Code is as follows: sprintf ("%f", 3.1415926); Result: "3.141593" but, sometimes we want to control the width and scale of the printing, then we should use: "%M.NF" format, where m represents the overall width of the printed number, n represents the number of digits after the decimal point. For example: The code is as follows: sprintf ("%9.3f", 3.1415926); Right alignment: The number of digits is not enough to complete with spaces. Results: "3.142" sprintf ("%-9.3f", 3.1415926); Left-aligned: the number of digits is not enough to complete with spaces. Results: "3.142" sprintf ("%.3f", 3.1415926); Do not specify the total width, result: "3.142" notice a problem code as follows: $num = 100; sprintf ("%.2f", $num); sprintf ("%.2f", (double) $num); Are the two results really the same? Although it looks the same, the following reasons may be instructive. The reason for this is that the caller does not know that the format control character corresponding to Num is a "%f" when the parameter presses the stack. The function is not aware of the execution of the stack is a whole number of times, so the poor save the integer $num of the 4 bytes were use robust reporting forced as a floating-point format to explain the whole mess.