You should use the new format specifications to define how your value should be represented:

>>> from math import pi  # pi ~ 3.141592653589793
>>> '{0:.2f}'.format(pi)
'3.14'

The documentation can be a bit obtuse at times, so I recommend the following, easier readable references:

  • the Python String Format Cookbook: shows examples of the new-style .format() string formatting
  • pyformat.info: compares the old-style % string formatting with the new-style .format() string formatting

Python 3.6 introduced literal string interpolation (also known as f-strings) so now you can write the above even more succinct as:

>>> f'{pi:.2f}'
'3.14'
Answer from BioGeek on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
July 23, 2025 - Once such function is the floor() function which is used to round down the float value to the nearest integer. The to get exact two decimal places, the number is to be first multiplied by 100 before applying the floor() function.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3288381 โ€บ how-to-round-to-2-decimal-places-in-python
How to round to 2 decimal places in python | Sololearn: Learn to code for FREE!
Yes, you can use the round() function in Python to round a float to a specific number of decimal places. In your case, you can use round(number, 2) to round the number to 2 decimal places.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ rounding-to-two-decimal-places-in-pythonn
Rounding to Two Decimal Places in Python | Codecademy
In Python, we can use the built-in round function to round floating-point numbers to a specified number of decimal places. One of the features of Pythonโ€™s round() function is its implementation of โ€œround half to even,โ€ also known as ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ pythonic way to show 2 decimal places in f-strings?
r/learnpython on Reddit: Pythonic way to show 2 decimal places in f-strings?
January 13, 2018 -

I've got a number that needs to be rounded to 2 decimal places. Getting the round is easy, but if the number is a whole number or only has 1 digit beyond the decimal the rounding doesn't properly show 2 decimal places.

answer = 1
print(round(float(answer),2))

>> 1.0

I really like f-strings, so I would use this:

answer = 1
print(f"{round(float(answer),2):.2f}")

>> 1.00

Is there a neater or more readable method of doing this?

๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - Learn how to round a number to two decimal places in Python for improved precision using techniques like round(), format(), and string formatting techniques.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_string_formatting.asp
Python String Formatting
Add a placeholder where you want to display the price: price = 49 txt = "The price is {} dollars" print(txt.format(price)) Try it Yourself ยป ยท You can add parameters inside the curly brackets to specify how to convert the value: Format the price to be displayed as a number with two decimals: txt = "The price is {:.2f} dollars" Try it Yourself ยป
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to format a number to 2 decimal places in python?
How to Format a Number to 2 Decimal Places in Python? - AskPython
February 27, 2023 - It is pretty simple by using %f formatter or str.format() with โ€œ{:.2f}โ€ as a string and float as a number. Letโ€™s take a look at the first method. The %f formatter is used to input float values or numbers with values after the decimal place.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ python
Floating point numbers to two decimal places - possible with standard lib? - Python - The freeCodeCamp Forum
August 24, 2022 - Iโ€™m trying to get 2 decimal places of 0s (e.g, 9.00) in the budget app project. I tried using string formatting, but the program expects a floating point number, not a string. Casting it to a float results in a single .0 because thatโ€™s how floating point numbers work in Python - that gets ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
A: The quantize() method rounds to a fixed number of decimal places. If the Inexact trap is set, it is also useful for validation: >>> TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-round-to-2-decimal-places-in-python
How to Round to 2 Decimal Places in Python
August 22, 2022 - For rounded2, the num is rounded up to 2 decimal places. At the 2nd decimal place is 4, and the number after it is 5.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 6 ways to round floating value to two decimals in python
6 Ways to Round Floating Value to Two Decimals in Python
November 4, 2024 - By applying the .2f format specifier within the format() method and using the "{:.2f}" format string, the number is formatted to have two decimal places. The resulting formatted_number is then printed, which outputs 3.14 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-round-floating-value-to-two-decimals-in-python
How to Round Floating Value to Two Decimals in Python - GeeksforGeeks
July 23, 2025 - from decimal import Decimal, ... specifies that we want to round to two decimal places n2 = n1.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) print(n2) ......
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-round-down-to-2-decimals-a-float-using-python
How to round down to 2 decimals a float using Python?
August 29, 2023 - # input floating-point number ... to be followed to perform the desired task -. Create a variable to store the input floating-point number. Use the format() function (It gives back a formatted version of the input value that has been specified by the format specifier) to round ...
๐ŸŒ
TestMu AI Community
community.testmuai.com โ€บ ask a question
How can I format a decimal to always show 2 decimal places in Python? - TestMu AI Community
November 28, 2024 - How can I format a decimal to always show 2 decimal places in Python? I want to display values like: - 49 as 49.00 - 54.9 as 54.90 Regardless of the number of decimal places, I want to ensure that the decimal is always displayed with 2 decimal places. This is for displaying monetary values, ...
๐ŸŒ
Python Shiksha
python.shiksha โ€บ home โ€บ tips โ€บ 3 python ways to limit float up to two decimal places
3 Python ways to Limit float up to two decimal places - Python Shiksha
July 18, 2021 - But we can also use this % operator in Python print statements in order to restrict our floats up to two decimal places. b= 25.7587852 c=19.568231469 print("%.2f"%b) print("%.2f"%c) ... format() is a very useful method while programming in python ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-format-decimal-output-in-python-421895
How to format decimal output in Python | LabEx
Python offers multiple techniques for formatting decimal numbers: ## Classic formatting price = 19.99 print("Price: %.2f" % price)
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ limit-floats-to-two-decimal-points
Here is how to limit floats to two decimal points in Python
Here is an example of how to use ... decimal points y = "{:.2f}".format(x) print(y) # Output: "3.14"The format function takes a format string as the first argument and the value to format as the second argument....