+ 1

what does "%6.2f" means ?

what's 6 and .2 of %6.2f means ?

13th Jan 2021, 8:49 AM
RD:programmer
RD:programmer - avatar
2 odpowiedzi
+ 5
Mr. Unknown here 6 is integer digit values and .2 means decimal value up to 2 digits
13th Jan 2021, 9:15 AM
Shaurya Barnwal
+ 3
"%6.2f" is called a format specifier. It describes how a number should be formatted for either input (scanf) or output (printf). The 6 is the overall field width, in other words how many characters total including all spaces, digits and even the decimal point. The .2 indicates the precision, in other words how many digits come after the decimal point. It is counted as part of the 6 characters. So 3 of the 6 characters are used by the decimal portion. If the formatted number takes more than 6 characters to print, then printf will print the formatted number anyway and let it overflow the space. There was a recent discussion here of using "%8.2f" regarding rounding. https://www.sololearn.com/Discuss/2664146/?ref=app
13th Jan 2021, 9:34 AM
Brian
Brian - avatar