+ 5

How to add Before a float 0 and more?

I got to class Today and the Professor asked us to Code something. There is a float number 5.5 but in output should be 005.500 So i tried it with %03f but it only gives me 005.5? Can someone explain the way How the Logic in %f works?

4th Oct 2019, 5:38 PM
Robotic/Mechatronic Engineer
Robotic/Mechatronic Engineer - avatar
5 odpowiedzi
+ 5
Thank you very much ~ swim ~
4th Oct 2019, 6:21 PM
Robotic/Mechatronic Engineer
Robotic/Mechatronic Engineer - avatar
+ 5
Now i got it. Because there are 7 things, 6 digits and the one space where the "." (dot) is!!! Thank you so much!
5th Oct 2019, 3:36 PM
Robotic/Mechatronic Engineer
Robotic/Mechatronic Engineer - avatar
+ 3
And why exactly 7? Because you Start at 0 and have 6 numbers? rodwynnejones
4th Oct 2019, 6:12 PM
Robotic/Mechatronic Engineer
Robotic/Mechatronic Engineer - avatar
+ 2
float a = 5.5; printf("%07.3f", a); here:-http://www.cplusplus.com/reference/cstdio/printf/
4th Oct 2019, 6:11 PM
rodwynnejones
rodwynnejones - avatar