This article mainly describes the PHP sprintf and printf function usage difference analysis, need friends can refer to the following
Here's an example: rounding the two-bit code after the decimal point is as follows: <?php $num 1 = 21; Echo sprintf ("%0.2f", $num 1). " <br/> "; Output 21.00 $num 2 = 16.3287; Echo sprintf ("%0.2f", $num 2). " <br/> "; Output 16.33 $num 3 = 32.12329; Echo sprintf ("%0.2f", $num 3). " <br/> "; Output 32.12 ?> explanation%0.2f meaning: % indicates that the starting character 0 indicates that the vacancy is filled with 0 2, indicating that the decimal point must occupy two-bit f to convert to floating-point number &NBS P Convert character =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-% print percent symbol, do not convert. b integers are converted to binary. c integers into the corresponding ASCII characters. The D integer is turned into 10. F-Times precision numbers are converted to floating points. The o integer is converted into octal. The s integer is converted into a string. x integers are converted to lowercase 16. X integers are converted to uppercase 16. The difference between printf and sprintf 1. printf function: int printf (string format [, mixed args [, mixed ...]]) produces output according to format, WH The ICH is described in the documentation for SPRINTF (). Returns The length of the outputted string. Format the text after the output, such as: code as follows: $name = "Hunte"; $age =25; printf ("My name was%s, age%d", $name, $age); nbsp 2. sprintf function: &NBsp String sprintf (string format [, mixed args [, mixed ...]]) Returns A string produced according to the formatting string format. is similar to printf, but does not print, but instead returns formatted text, and others are the same as printf. 3. Print function: is a function that can return a value with only one argument. int print (string arg) outputs Arg. Returns 1, always.