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 trialDrew 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,454 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,454 PointsChris Freeman
Treehouse Moderator 68,454 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.