Free tools Windows power users keep installed
One-click scans. No signup required.
Use f'{value:.2f}' to display a number with exactly two digits after the decimal point. It returns formatted text; it does not change the number used by later calculations. If you need a rounded decimal value for arithmetic, use Decimal and quantize() with the rounding rule your application requires.
Print two decimal places with an f-string
The .2f format specifier means fixed-point notation with two digits after the decimal point. Put it inside an f-string to format a value:
As an Amazon Associate I earn from qualifying purchases.
price = 12.5
print(f"{price:.2f}") # 12.50
The result includes a trailing zero when needed. For instance, a value displayed as 12.50 still has two fractional digits even though its value could also be written as 12.5. Python’s floating-point tutorial uses format(math.pi, '.2f') to produce '3.14'.
Recommended Free Tools
Use format() for the same result
If you do not need to embed the value in a larger string, call format() directly:
#1 Best Overall
value = 12.5
text = format(value, ".2f")
print(text) # 12.50
Both approaches produce a string. Choose the f-string when combining the formatted number with other text, and format() when you want the formatted string by itself.
Formatting is not the same as rounding a value for later arithmetic
f'{value:.2f}' controls how the value is shown. It does not mutate the original number, nor does it ensure later calculations use a value rounded to two places. Keep the distinction clear:
Rank #2
- Display: format a number as text with
.2f. - Calculation: if later arithmetic must use a decimal amount rounded to two places, create a
Decimalvalue and quantize it.
Why formatting a float can surprise you
Python’s float type uses binary floating-point. Many decimal fractions, including 0.1, cannot be represented exactly in binary. Formatting a float therefore rounds its stored binary approximation, not necessarily the exact decimal value you had in mind when entering it. This can make apparent halfway cases behave unexpectedly. The Python tutorial explains that this is a property of binary floating-point, not a Python bug: Floating-Point Arithmetic: Issues and Limitations.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsFor ordinary display, .2f still gives two digits after the decimal point. The caveat matters when the precise decimal input and a particular rounding policy are important.
Use Decimal for controlled decimal rounding
When the written decimal value should be retained, construct a Decimal from a string rather than first converting the value to a float. Then use quantize() to set the required number of decimal places and, where necessary, specify the rounding mode:
from decimal import Decimal, ROUND_HALF_UP
amount = Decimal("2.675")
rounded = amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
print(f"{rounded:.2f}") # 2.68
Here, Decimal('0.01') sets the result’s exponent to two decimal places, and ROUND_HALF_UP explicitly selects the rounding policy for this operation. The Python decimal documentation describes quantize(), context rounding, and fixed-point formatting for Decimal values.
Do not assume one rounding mode is right for every financial, regulated, or other application. Choose the policy required by your use case. With Decimal, round(number, ndigits) follows the active decimal context’s rounding mode and is equivalent to quantizing to the matching power of ten.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
Best Value
Which approach should you use?
| What you need | Use | What it does |
|---|---|---|
| Show a number with two fractional digits | f'{value:.2f}' or format(value, '.2f') |
Returns text formatted to two decimal places. |
| Round decimal input for subsequent calculations | Decimal with quantize() |
Returns a Decimal rounded to the requested exponent using the selected or active rounding mode. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




