I might be misunderstanding you, but is this what you want?

>>> print '{:.2f} {:<20}'.format(1.0, 'kg/hr')
1.00_kg/hr_______________
Answer from TerryA on Stack Overflow
🌐
Towards Data Science
towardsdatascience.com › home › programming › formatting strings and numbers in python
Formatting strings and numbers in python | Towards Data Science
June 27, 2021 - You can use the :>, :< or :^ option in the f-format to left align, right align or center align the text that you want to format. ... After formatting the alignment of output text ...
Discussions

Left-justifying floating-point number output
Question: Is the “-” in the format used below supposed to left-justify the number? Code: This section is just generating numbers to demonstrate the problem. def neuralNetwork(input, weight): prediction = input * weight return prediction ​weight = 0.5 goalPrediction = 0.8 input = 0.5 for ... More on discuss.python.org
🌐 discuss.python.org
4
0
November 5, 2021
python - align float and specify precision in string formatting - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Python: Format string with float, right alignment - Stack Overflow
I want to align a combination of str and float to the right side. In my example, "Tax = $" is a string and tax is a float. I have two ways to accomplish this. print(("Tax = $%.2f" % tax).rjust(70)) More on stackoverflow.com
🌐 stackoverflow.com
How do I right-justify strings with dollar signs and percentages?
"Formatting doesn't seem to do literally anything at all." Well, all of Python's number formatting methods allow you to restrict the output to two decimal places and to right justify it. I suggest that you post your code so that people here can advise you what is going wrong with it. You can edit your original post to include it. Guide to posting code in this subreddit: https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F More on reddit.com
🌐 r/learnpython
8
3
February 13, 2022
People also ask

How do you format a float to two decimal places in Python?
Use f"{value:.2f}" in modern code, "{:.2f}".format(value) with str.format(), or "%.2f" % value in percent-style formatting.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python string format
Python String Format: f-strings, format(), %, Padding, and Precision
Is percent formatting deprecated in Python?
No. It is old-style or legacy formatting, but Python still documents printf-style string formatting for reading and maintaining older code.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python string format
Python String Format: f-strings, format(), %, Padding, and Precision
What is the best way to format strings in Python?
Use f-strings in Python 3.6 and later for most new code. They are readable and support variables, expressions, and format specifiers inside braces.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python string format
Python String Format: f-strings, format(), %, Padding, and Precision
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-format-a-floating-number-to-fixed-width-in-python
How to format a floating number to fixed width in Python?
March 24, 2026 - Zero Padding (0): Pads the number with zeros on the left side instead of spaces. number = 838.65 # Right align with spaces (default) right_align = "{:>10}".format(number) print('Right Align:', right_align) # Left align with spaces left_align = "{:<10}".format(number) print('Left Align: ', left_align) # Center align with spaces center_align = "{:^10}".format(number) print('Center Align:', center_align) # Zero padding zero_padding = "{:010.2f}".format(number) print('Zero Padding:', zero_padding)
🌐
Note.nkmk.me
note.nkmk.me › home › python
Right-justify, Center, Left-justify Strings and Numbers in Python | note.nkmk.me
May 18, 2023 - If you want to right-justify, center, or left-justify a non-string object such as an integer (int) or floating point number (float), convert it to a string with str() and call these methods. i = 123 print(type(i)) # <class 'int'> print(str(...
🌐
Python.org
discuss.python.org › python help
Left-justifying floating-point number output - Python Help - Discussions on Python.org
November 5, 2021 - Question: Is the “-” in the format used below supposed to left-justify the number? Code: This section is just generating numbers to demonstrate the problem. def neuralNetwork(input, weight): prediction = input * weight return prediction ​weight = 0.5 goalPrediction = 0.8 input = 0.5 for iteration in range(124): prediction = neuralNetwork(input, weight) error = (prediction - goalPrediction) ** 2 directionAndAmount = (prediction - goalPrediction) * input weight = weight - directionA...
🌐
Stack Abuse
stackabuse.com › formatting-strings-with-python
Formatting Strings with Python
July 17, 2023 - >>> f"{left_aligned:><15}{center:-^10}{right_aligned:<>15}" 'Left Align>>>>>-Centered-<<<<Right Align' Formatting floating point numbers, those containing decimal places, is a cinch in Python.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python string format
Python String Format: f-strings, format(), %, Padding, and Precision
June 23, 2026 - Each line builds a formatted string with a different style. For appending text without full formatting rules, see Append string in Python. String formatting inserts values into a string. It can also control width, alignment, padding, decimal places, signs, commas, percentages, and dates.
Find elsewhere
🌐
pythontutorials
pythontutorials.net › blog › align-float-and-specify-precision-in-string-formatting
How to Align Float and Specify Precision in Python String Formatting Using a Single Argument — pythontutorials.net
pi = 3.14159 # Right-align (default for numbers) with width=10 print(f"Right-aligned: {pi:10}") # Output: Right-aligned: 3.14159 # Left-align with width=10 print(f"Left-aligned: {pi:<10}") # Output: Left-aligned: 3.14159 # Center-align with width=10 print(f"Center-aligned: {pi:^10}") # Output: Center-aligned: 3.14159 · Note: Without a precision specifier, Python uses the float’s default string representation. The real power of Python’s formatting syntax is combining alignment and precision into a single format specifier.
🌐
GeeksforGeeks
geeksforgeeks.org › string-alignment-in-python-f-string
String Alignment in Python f-string - GeeksforGeeks
March 22, 2025 - Python’s f-strings make it easy ... text alignment using three primary alignment specifiers: < (Left Alignment): Aligns the text to the left within the specified width....
🌐
Python Guides
pythonguides.com › python-string-formatting
Python Tutorials: Learn Python for Free | Python Guides
February 14, 2025 - Every example is run in Python 3 before it’s published, and the real output is shown under the code.
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
March 18, 2026 - These allow you to left, right, and center-align the number within the width value, respectively. You may have noticed that only three space characters have been added, instead of the four you saw earlier. This is because by including the thousands separator in your format specifier, you have used up an additional character space.
🌐
Educative
educative.io › answers › how-to-format-strings-in-python
How to format strings in Python
The following example converts an integer to float: print("Employee at Educative ate {0:f} percent of a {1}!".format(75, "pizza")) ... Any value (integer, number, string or character) can be padded from left and right.
🌐
PyFormat
pyformat.info
PyFormat: Using % and .format() for great good!
The old style defaults to right aligned while for new style it's left. ... Again, new style formatting surpasses the old variant by providing more control over how values are padded and aligned.