Created: 2023-01-11 11:18
Status: #concept
Subject: Programming
Tags: C stdio.h Format String
Precision
It’s the
.p
in the %m.pX
placeholder to indicate specific formatting, depending on the Conversion Specifiers.
Example
printf("%10.2d\n", 3);
printf("%10.2e\n", 3.142f);
printf("%10.2f\n", 3.142f);
printf("%10.2g\n", 3.142f);
/*** OUTPUT ***/
03
3.14e+00
3.14
3.1
The
g
Conversion Specifier is useful when we are unsure whether the output will be big or small.
It will automatically use decimal points for small numbers & exponents for larger floating-point numbers, according to the amount of significant numbers specified by the precision.
References
- C Programming, A Modern Approach, 2nd Edition, Chapter 3.1