Zhigang Wang
  • Home
  • Blog
  • Wiki
  • LDP
  • Planet

Printf Formating

Last modified on 2009-12-01

Printf is used frequently used in C programming language. But the format string is the same in Python "print" statement, and also can be used in Bash builtin command "printf" or "printf" tool from coreutils. So it's really worth learning.

Format identifers list:

	%d %i	Decimal signed integer.
	%o	Octal integer.
	%x %X	Hex integer.
	%u	Unsigned integer.
	%c	Character.
	%s	String.	See below.
	%f	double
	%e %E	double.
	%g %G	double.
	%p	pointer.
	%n	Number of characters written by this printf.
		No argument expected.
	%%	%. No argument expected.

Flags:

	-	Left justify.
	0	Field is padded with 0's instead of blanks.
	+	Sign of number always O/P.
	blank	Positive values begin with a blank.
	# 	Various uses:
			%#o (Octal) 0 prefix inserted.
			%#x (Hex)   0x prefix added to non-zero values.
			%#X (Hex)   0X prefix added to non-zero values.
			%#e         Always show the decimal point.
			%#E         Always show the decimal point.
			%#f         Always show the decimal point.
			%#g         Always show the decimal point trailing 
				    zeros not removed.
			%#G         Always show the decimal point trailing
				    zeros not removed.

Reference

  1. Printf on Wikipedia.
  2. String Formatting Operations of Python.
 

Categories

  • All contents
  • English contents
  • Chinese contents

Feeds

  • AtomAll contents
  • AtomEnglish contents
  • AtomChinese contents

Tags

  • gtd
  • syslog
  • twiki
  • virtualizaion
  • wiki
  • xen

Copyright © 2012 Zhigang Wang. Some right reserved.

The views expressed on this web site are my own and do not necessarily reflect the views of Oracle.