Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
krishna sapkal
Courses Plus Student 53 Pointswhat does the %0.6f do in c?
what does the %0.6f do in c?
2 Answers
Steve Hunter
57,712 PointsHiya,
It is many years since I touched the C language! Something like:
printf("%0.6f", varName);
I think that prints the variable varName (which is storing a float) as a number like 1.123456 rather than in any odd notation. Also, you can specify the total length of the whole number representation, as well as the number of decimal places. So, %5.2f will limit the number to five digits and, if there's room, 2 decimal places.
A quick Google will get you lots of examples that are better placed to help than I am! Here, here and here
Regarding accuracy, have a look at this Treehouse post that covers the strange results you get with floats.
Steve.
Steve Hunter
57,712 PointsHi there,
I think that formats a floating point number to show six decimal places.
Steve.
krishna sapkal
Courses Plus Student 53 Pointscan you show me the example code
krishna sapkal
Courses Plus Student 53 Pointskrishna sapkal
Courses Plus Student 53 Pointstysm