I need to format a float to the format +-00.00, tried the basic string formatting but can’t get the leading + or – sign or two leading 0s if the value is fractional, any pointers?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Use
'%+06.2f'to set the width and precision appropriately. The equivalent using new-style format strings is'{:+06.2f}'.format(n)(or'{0:+06.2f}'if your version of Python requires the positional component).