printf 字符宽度 小数点后小数位数 格式输出

#include <stdio.h>
int main(void)
{
	printf("%d\n", 6);
	printf("%4d\n", 6);			/*至少4位字符宽*/
	printf("%03d\n", 6);		/*至少3位字符宽,且不足则补0*/
	printf("%04d\n", 6);

	printf("%02x\n", 19);		/*至少2位字符宽,16进制输出,不足则补0*/

	printf("%f\n", 6);

	printf("%f\n", 6.0);

	printf("%9f\n", 6.0);
	printf("%9.2f\n", 6.0);	/*至少9位字符宽,小数点后两位小数*/
	printf("%09.2f\n", 6.0);

	return 0;
}

 

image
posted @ 2012-11-21 20:46  helloweworld  阅读(2027)  评论(0编辑  收藏  举报