Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Print 2 Decimal Places in Python: `.2f`, `round()` and `Decimal`

Use Python’s `.2f` format specifier to display two decimal places. For controlled decimal rounding in calculations, use Decimal and quantize().

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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'.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use format() for the same result

If you do not need to embed the value in a larger string, call format() directly:

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:

  • Display: format a number as text with .2f.
  • Calculation: if later arithmetic must use a decimal amount rounded to two places, create a Decimal value 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.