• printf%[flags][width][.prec][hlL]type |Flag|含义|width 或 prec|含义|hlL|含义| |:-:|:-:|:-:|:-:|:-:|:-:| |-|左对齐|number|最小字符数|hh|一个字节| |+|显示符号|* |变量待定字符数|h|short| |(space)|正数留空|.number|保留小数位数|l|long| |0|填充0|.* |变量待定保留小数位数|ll|long long| |||||L|long double|
  • scanf%[flag]type |flag|含义|flag|含义| |:-:|:-:|:-:|:-:| |* |跳过|l|long, double| |数字|最大字符数|ll|long long| |hh|char|L|long double||h|short|||
type用于type用于
i 或 dintf 或 Ffloat, 6
uunsigned intgfloat
o八进制Gfloat
x 或 X小大写十六进制a 或 A十六进制浮点
e 或 E下大写指数p指针
cchars字符串
n读入/写出的个数
int num;
pritnf("%dll%n --> ",12345,&num);
printf("%d",num);		// 12345ll --> 7

保留小数位数

%.[位数]f

  • 定位数默认7位有效数字?

  • 的答案是四舍五入的 就是说, 真实值还是那个000001或者99999

double s=-0.0049;
 
printf("%.3f\n",s);		// -0.005
printf("%.30f\n",s);	// -0.004899999999999999800000000000
printf("%.2f",s);		// -0.00