+ 2

How does this one work:

printf("Pi = %8.5f", 3.14159); /* Pi = 3.14159 */ I thought the 8 in there specifies the minimum width, in which case wouldn't the input of 3.14159 be too short?

9th Jun 2020, 3:31 PM
Smiley[Offline]
3 Answers
0
With 8 you specify the absolute width. If your number is shorter, it will be right-aligned on a space of 8. The minimum means, that the number will not be truncated, should it be longer.
9th Jun 2020, 4:00 PM
HonFu
HonFu - avatar
+ 1
i still cant understand https://code.sololearn.com/cV5gIbweeDNK output is Pi = 123456789.12
10th Jun 2020, 2:32 AM
Smiley[Offline]
+ 1
Check these... printf("Pi = %08.2f \n", 9.12345 ); In 08.5f 0 is filled in to stretch value atleast length of 8 digits including dot. Ex: observe output... printf("Pi = %08.2f \n", 3.1 ); printf("Pi = %08d \n", 3 ); printf("Pi = %08.2f \n", 12.12345 );
10th Jun 2020, 5:53 PM
Jayakrishna 🇼🇳