When i compiles a program with this code:
int main()
{
float a;
scanf("%f", &a);
printf("%.1f\n", a); //Here
return 0;
}
There is no difference with this other:
int main()
{
float a;
scanf("%f", &a);
printf("%.01f\n", a); //Here
return 0;
}
Anybody can tell me why?
The number behind the period is the precision that specifies the number of digits after the decimal point of a floating-point value. The leading zero has no meanings.
The number before the period is the number that specifies the minimum field width. The leading zero will change the padding character from white space to 0.
The digits after the decimal point specify the precision - the minimum number of digits which will be written. .1 and .01 both say to put at least 1 digit, and to pad the result with zeros if there is fewer than 1 digit. Plain %f is equivalent to %.6f, i.e. 6 digits after the decimal point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With