Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 536353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:48:46+00:00 2026-05-13T09:48:46+00:00

I always have to know why, rather than just how, so here I go:

  • 0

I always have to know why, rather than just how, so here I go:

How does this work:

'{0:01.2f}'.format(5.555)  #returns '5.55'

'{0:01.1f}'.format(5.555)  #returns '5.5'

'{0:1.2f}'.format(5.555)   #returns '5.55' again

'{0:1.1f}'.format(5.555)   #returns '5.5' again

Why does this not add zero padding by returning ‘05.5’ instead of just ‘5.5’ when I have the extra zero. It just doesn’t seem to work.

Also, why is the string 0:1.1f instead of 0:0.1f, etc. Is it just a convention to use the number 1 before the decimal instead of a zero, or is that the syntax?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:48:47+00:00Added an answer on May 13, 2026 at 9:48 am

    Its because the 0 character enables zero-padding, but you have a width of 1 set. Set the width to 2 (like '{0:02.1f}' and you will see a leading 0.

    Edit – actually, I’m not sure if 2 will suffice, because I don’t know how it behaves with more digits after the decimal point. So to be safe, make it something like 5 and see what it does then.

    Edit 2 – ok, I just tried it. The width corresponds to the TOTAL width, including all digits and the decimal point. So you’ll get this:

    >>> '{0:05.2f}'.format(5.555)
    '05.55'
    

    Note that the total length of the string is 5 now, with a leading 0 because zero-padding is enabled, and that it truncates to 2 digits after the decimal point because of .2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Toyota manufacturing lines they always know what path a part have traveled. Just
I have a subclass with an over-ridden method that I know always returns a
I always have this notion that writing SQL queries in the code behind is
I always have heard this motto from many entrepeneurs: do what you are passionate
This is more out of curiosity than anything else, as I have solved my
I have a theory question rather than an error report. I'm a rookie C++
I've been developing .net console applications using C# and have always just dictated what
I always have found the open source space interesting but have never actually participated
I seem to always have problems with converting data to and from XML in
When I have one app.config in my main project I always have to duplicate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.