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
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to use the float() command to create 2 decimal places instead of one in a product of 2 numbers [the product is dollar amount]
r/learnpython on Reddit: How to use the float() command to create 2 decimal places instead of one in a product of 2 numbers [the product is dollar amount]
January 28, 2020 -

Example:

hourlyRate = 20 hoursLabor = 1.6

I want the answer to show โ€œ32.00โ€ instead of โ€œ32โ€ or โ€œ32.0โ€.

What I have so far produces the number 32.0:

totalPay = float(hourlyRate * hoursLabor)

print(totalPay)

Iโ€™m obviously very new at this. Just getting some beginnerโ€™s practice :)

How to format to two decimal places python Apr 29, 2021
r/learnprogramming
5y ago
What does the float function do? Sep 9, 2020
r/learnpython
5y ago
Rounding two decimal places using Printf Sep 22, 2015
r/learnprogramming
10y ago
Is a float just a number with a decimal point? (Python) Jun 14, 2020
r/learnprogramming
6y ago
More results at reddit.com
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ rounding-to-two-decimal-places-in-pythonn
Rounding to Two Decimal Places in Python | Codecademy
In Python, the % operator, also called modulus operator, We can use this operator for string formatting to round values to a specific number of decimal places. Known as old-style or printf-style formatting, this approach uses format specifiers ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ precision-handling-python
Precision Handling in Python - GeeksforGeeks
August 9, 2024 - Using format() - This is yet another way to format the string for setting precision. Using round(x,n) - This function takes 2 arguments, number, and the number till which we want the decimal part rounded.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-print-2-decimal-places
How to Print Two Decimal Places in Python
December 22, 2025 - They were introduced in Python 3.6 and have completely changed how I write code. They are fast, readable, and allow you to format numbers directly within the string. # Monthly subscription cost for a streaming service in the USA monthly_fee = 14.991234 # Using an f-string to format to 2 decimal places formatted_fee = f"Your monthly subscription is: ${monthly_fee:.2f}" print(formatted_fee) # Output: Your monthly subscription is: $14.99
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ hardware and peripherals โ€บ raspberry pi pico โ€บ micropython
Formatting decimal places from sensor values in micropython - Raspberry Pi Forums
March 7, 2023 - bme = bme280.BME280(i2c=i2c) temp = bme.values[0] print(bme.values) print(temp) #temp = "17.46645466536C" temp_removeC = temp[:-1] ##this 'strips' the last character off the end, -3 for three characters print(temp_removeC) temperature = float(temp_removeC) ##//this makes the string a decimal point number temperature_formatted_string = "{:.2f}".format(temperature) ##//this sets the decimal places, but is now a string again print(temperature_formatted_string) #temp = "17.466536C" temperature_formatted_string = "{:.1f}".format( float(temp[:-1])) print(temperature_formatted_string + "C" ) ('17.57C', '989.76hPa', '44.65%') 17.58C 17.58 17.58 17.6C (I added the C back, and reduced decimals to one place.)
Find elsewhere
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ built-in-methods โ€บ format-2-decimal-places
How to Format a Number to 2 Decimal Places in Python? - AskPython
February 27, 2023 - In this article, we learn how to format a number to 2-decimal places by using two ways. You can show the result using %f formatted, written inside quotation marks, and the % modulo operator separates it from the float number โ€œ%fโ€ % num.
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ string โ€บ python-data-type-string-exercise-30.php
Python: Print the following floating numbers upto 2 decimal places - w3resource
June 12, 2025 - # Define a variable 'x' and assign ... line for spacing. print() # Print the original value of 'x' with a label. print("Original Number: ", x) # Format the value of 'x' to two decimal places and print it with a label. ...
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_data_types_dec.php
C Data Types Decimal Precision
float myFloatNum = 3.5; printf("%f\n", myFloatNum); // Default will show 6 digits after the decimal point printf("%.1f\n", myFloatNum); // Only show 1 digit printf("%.2f\n", myFloatNum); // Only show 2 digits printf("%.4f", myFloatNum); // Only ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ 2f-in-python-what-does-it-mean
%.2f in Python โ€“ What does it Mean?
June 22, 2022 - floatNumber = 1.9876 print("%.1f" % floatNumber) # 2.0 ยท In the code above, we added .1 between % and f in the %f operator. This means that we want the number to be rounded up to one decimal place.
๐ŸŒ
Python Guides
pythonguides.com โ€บ round-numbers-to-2-decimal-places-in-python
How To Round Numbers To 2 Decimal Places In Python?
January 16, 2025 - In this example, we create a Decimal object from a string and use the quantize() method to round it to 2 decimal places. The rounding parameter is set to ROUND_HALF_UP , which rounds numbers ending in 5 up (away from zero).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
December 16, 2024 - Now let us see different ways to get two decimal places in Python one by one. ... The f-string in Python is used to format a string. It can also be used to get 2 decimal places of a float value.
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ how to display 2 decimal places in python | example code
How to display 2 decimal places in Python | Example code
January 11, 2023 - Simple example code use str.format(number) with โ€œ{:.2f}โ€ as a string and float as a number to return a string representation of the number with two decimal places. fnum = 7.154327 res = "{:.2f}".format(fnum) print(res) Output: Answer: Use ...
๐ŸŒ
The Teclado Blog
blog.teclado.com โ€บ python-formatting-numbers-for-printing
Formatting Numbers for Printing in Python - The Teclado Blog
September 2, 2019 - Learn how to leverage Python's detailed formatting language to control how numbers are displayed in your applications.
๐ŸŒ
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 ...
๐ŸŒ
CodeGenes
codegenes.net โ€บ blog โ€บ how-to-print-2-decimal-places-in-python
Printing 2 Decimal Places in Python: A Comprehensive Guide โ€” codegenes.net
Use rounding when appropriate, ... in Python can be achieved using various methods, including the format() method, f - strings, and the round() 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 is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-get-2-decimal-places-in-python
How to Get 2 Decimal Places in Python - Javatpoint
How to Get 2 Decimal Places in Python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.