Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Drew Butcher
33,160 PointsString Format
in the {:03.2f}
what does the 03 do? I receive the same result with just {:0.2f}
1 Answer

Chris Freeman
Treehouse Moderator 68,154 Points{:03.2f}
says "three or more total digits, two digits after the period. Since a float will always have at least one digit in front of the period, {:03.2f}
, {:02.2f}
, {:01.2f}
, and {:0.2f}
are all equivalent.
Edit: corrected answer based on James Shi's comment.
James Shi
8,942 PointsJames Shi
8,942 PointsTechnically this is wrong. The 3 means at least 3 characters. The 0 means if there aren't at least 3 characters, pad zeros in front of the number to increase the amount of characters to 3. You only need
{:.2f}
.Chris Freeman
Treehouse Moderator 68,154 PointsChris Freeman
Treehouse Moderator 68,154 PointsJames Shi, you are correct! Yes, the "3" does mean "three or more characters".
Part of my point was that with the ".2f" present, the a width value of three or less is equivalent:
Thanks for catching this error. I'll update the answer above.