October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Round Numbers to 2 Decimal Places in Python

Use round(value, 2) for a numeric result, .2f formatting for exactly two displayed digits, and Decimal.quantize() when decimal arithmetic rules matter.

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 round(value, 2) when you need a numeric result rounded to two decimal places. For example, round(3.14159, 2) returns 3.14. If you need exactly two digits for display, including a trailing zero, format the value instead: f'{value:.2f}'. For decimal-sensitive arithmetic, use Decimal and quantize().

Use round() for a numeric result

The built-in round(number, ndigits) function rounds a number to the requested number of digits after the decimal point when ndigits is positive. Pass 2 for two places:

value = 3.14159
rounded = round(value, 2)
print(rounded)  # 3.14

The result remains a number, which is useful for subsequent calculations. Omitting the second argument, as in round(value), rounds to an integer instead. Python’s built-in rounding uses ties-to-even when a value is exactly halfway between two choices: for example, round(0.5) is 0 and round(1.5) is 2. See the Python 3.14.8 built-in functions documentation.

Why can round(2.675, 2) return 2.67?

Python’s usual float type stores numbers in binary floating-point, and many decimal fractions cannot be represented exactly in binary. The float stored for the literal 2.675 is slightly below the exact decimal value, so round(2.675, 2) produces 2.67. This reflects the stored value, not a defect in round(). The Python floating-point tutorial explains the representation issue.

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

Choose the method for your goal

Goal Use What you get
Round for further numeric calculations round(value, 2) A number; exact halfway cases use ties-to-even, and float representation may affect the result. Python documentation
Perform decimal-sensitive arithmetic Decimal('...').quantize(Decimal('0.01')) A decimal value with two fractional places; the active or specified decimal rounding mode applies. Python decimal documentation
Display exactly two digits format(value, '.2f') or f'{value:.2f}' Text with two digits after the decimal point, including trailing zeros.

Format a value when the digits are for display

Rounding a number does not guarantee that it will be displayed with two trailing digits. To display 3.1 as 3.10, use a fixed-point format:

value = 3.1
print(f'{value:.2f}')  # 3.10
print(format(value, '.2f'))  # 3.10

These formatting operations produce strings, not numbers for arithmetic. Keep the numeric value for calculations and format it when presenting output.

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

Use Decimal when decimal rules matter

For amounts or other decimal-sensitive calculations, construct a Decimal from the original decimal text, then quantize it to the exponent 0.01:

from decimal import Decimal

amount = Decimal('2.675')
rounded_amount = amount.quantize(Decimal('0.01'))
print(rounded_amount)  # 2.68

With the default decimal context, this example uses ROUND_HALF_EVEN. quantize() follows the active context’s rounding mode unless you specify a mode; select one explicitly if your application requires a different rule. Do not pass a float when you mean the original decimal input: Decimal(2.675) carries in the float’s approximation, while Decimal('2.675') represents that decimal text exactly. The Python decimal documentation describes construction, quantization and rounding modes.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.