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 或 d | int | f 或 F | float, 6 |
u | unsigned int | g | float |
o | 八进制 | G | float |
x 或 X | 小大写十六进制 | a 或 A | 十六进制浮点 |
e 或 E | 下大写指数 | p | 指针 |
c | char | s | 字符串 |
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