What is the use of first digit in format specifier? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the use of first digit in format specifier?

printf("pi=%3.2f", 3.1456) Here if 3 is the width, I gave 3124.1456 as the input. But I got the answer as itself. It didn't cut off 4.

11th Jan 2019, 2:44 PM
Mohamed Burhan
Mohamed Burhan - avatar
8 Answers
+ 5
The first digit gives the overall *minimal* width including dot that your number is supposed to occupy. If it's longer, you just don't see any effect. Change the number to 10 and there'll be a whitespace gap. If you don't want that, just write: %.2
11th Jan 2019, 3:01 PM
HonFu
HonFu - avatar
+ 3
10 in your format-specifier! %10.2f First number is total minimal width, second number is digits after the dot.
11th Jan 2019, 3:36 PM
HonFu
HonFu - avatar
+ 2
I have explained that in the first post. Please try what I just wrote and see if you get it!
11th Jan 2019, 3:38 PM
HonFu
HonFu - avatar
+ 2
Because 10 is not a float. That's a different error.
11th Jan 2019, 3:44 PM
HonFu
HonFu - avatar
+ 1
Do you mean it is the number of total characters. But when I gave 10 why didn't it give 10.00. It just gave 0.00
11th Jan 2019, 3:43 PM
Mohamed Burhan
Mohamed Burhan - avatar
+ 1
Thanks a lot brother. I got you 👍🙂
11th Jan 2019, 3:45 PM
Mohamed Burhan
Mohamed Burhan - avatar
0
I gave 10, I got the answer as 0.00. I still don't understand what happens. Pls explain me.
11th Jan 2019, 3:08 PM
Mohamed Burhan
Mohamed Burhan - avatar
0
What is minimal width?
11th Jan 2019, 3:37 PM
Mohamed Burhan
Mohamed Burhan - avatar