Home >Backend Development >PHP Tutorial >PHP printf output format usage sharing

PHP printf output format usage sharing

WBOY
WBOYOriginal
2016-07-25 08:57:151435browse
  1. main()
  2. { int a = -1;
  3. printf("%d, %o", a, a);
  4. }
Copy code

Run result: -1,177777 Program analysis: -1 in the memory unit (stored in complement form) is (1111111111111111)2, and converted to octal number is (177777)8. ③x format: Output integers in unsigned hexadecimal form. Long integers can be output in "%lx" format. You can also specify the field width to output in "%mx" format. ④u format: Output integers in unsigned decimal form. Long integers can be output in "%lu" format. You can also specify the field width to output in "%mu" format. ⑤c format: output one character. ⑥s format: used to output a string. There are several ways to use it

  1. printf("%f%%", 1.0/3);
Copy the code

to output 0.333333%.

Explanation on single precision and double precision: 1. Single precision number. When output using the %f format character, only the first 7 digits are significant digits and there are 6 decimal digits. 2. When a double precision number is output using the %lf format character, the first 16 digits are valid digits and there are 6 decimal places.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn