Last modified: Nov 16, 2026

Python Round to 2 Decimal Places

Rounding numbers is a common task in Python. You often need clean prices, scores, or measurements. Showing many decimal places looks messy. So you round to 2 decimal places.

This guide shows the main ways to do it. You will see simple code and clear output. Each method has its own use case. By the end, you will know which one to pick.

Why Round to 2 Decimal Places?

Most currencies use two decimals. Prices like 19.99 look natural. Long floats like 19.994999 look like bugs. Rounding fixes that.

Rounding also helps when you display data. Reports and dashboards read better with short numbers. You keep the value readable without losing much precision.

Remember that rounding changes the number. It is not the same as cutting off digits. Python rounds to the nearest value. The result depends on the digits after the second decimal.

Method 1: Use the round Function

The built-in round function is the simplest option. It takes a number and the number of decimals. It returns a new rounded value.


# Round a float to 2 decimal places
price = 19.9949
rounded = round(price, 2)
print(rounded)

19.99

You can also round up or down based on the third digit. Here the third digit is 4, so the result goes down.


# The third decimal decides the rounding
print(round(3.456, 2))  # 3.46 (third digit is 6)
print(round(3.454, 2))  # 3.45 (third digit is 4)

3.46
3.45

The round function returns a float. That is fine for math. But it may drop trailing zeros. For example, 2.5 becomes 2.5, not 2.50. If you need fixed decimals for display, use a string method.

Passing arguments to functions like this is a core skill. If you want a deeper look, read about how Python function arguments work.

Method 2: Use the format Method

The format method turns a number into a string. You control the decimals with a format spec. The pattern ".2f" means two digits after the point.


# Format a float with exactly 2 decimals
value = 7.1
text = format(value, ".2f")
print(text)
print(type(text))

7.10

Notice the output is a string. It keeps the trailing zero. This is great for prices and labels. It is not good for more math, because strings cannot be added or multiplied.

You can also round up here. The format method follows the same nearest-value rule.


# Formatting rounds to the nearest value
print(format(2.675, ".2f"))
print(format(2.674, ".2f"))

2.67
2.67

The first line may surprise you. Floating point storage makes 2.675 slightly smaller. So it rounds down. This is a known Python behavior, not a bug in your code.

Method 3: Use an f-string

F-strings are the modern way to format text. You put the format spec inside the braces. The result is a clean string with two decimals.


# f-string with a 2-decimal format spec
total = 123.4567
message = f"Total: {total:.2f}"
print(message)

Total: 123.46

F-strings are short and readable. They are the best choice for user-facing output. Use them in print calls, logs, and templates.

You can combine them with other data. This keeps your code tidy and avoids long concatenations.


# Combine text and rounded numbers
item = "Coffee"
cost = 4.5
line = f"{item}: ${cost:.2f}"
print(line)

Coffee: $4.50

If you ever store rounded values in a collection, the type matters. Sets and lists behave very differently. See the key differences between sets and lists before you choose one.

Method 4: Use Decimal for Exact Results

Floats can be imprecise. Money math often needs exact rounding. The Decimal class from the decimal module solves this.


from decimal import Decimal, ROUND_HALF_UP

# Use Decimal for exact money rounding
amount = Decimal("2.675")
rounded = amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
print(rounded)

2.68

Here the result is 2.68, not 2.67. You control the rounding rule. This is important for invoices and payments.

Always create Decimal values from strings. Passing a float can carry the same precision problem you are trying to avoid.


# Good: string input
good = Decimal("10.005")

# Risky: float input
risky = Decimal(10.005)
print(good)
print(risky)

10.005
10.00499999999999989341858963598497211933135986328125

The second value shows the hidden float noise. That is why string input is the safe pattern.

Rounding Integers and Negative Numbers

Integers have no decimals. Rounding them to 2 places returns the same integer. You can still call the function, but it adds nothing.


# Integers stay the same
print(round(42, 2))

42

Negative numbers also work. The rule is the same. The value moves to the nearest hundredth.


# Negative values round too
print(round(-3.456, 2))
print(round(-3.454, 2))

-3.46
-3.45

Common Mistakes to Avoid

Do not compare rounded floats with ==. Two floats may look equal but differ in tiny bits. Use a small tolerance instead.

Do not use strings for math. If you format a number, convert it back with float before you calculate.

Do not assume bankers rounding. Python rounds half to even. So 2.5 becomes 2 and 3.5 becomes 4. Use Decimal if you need half-up rules.

Also watch out for display vs storage. Store full precision and round only for output. This keeps your data accurate over many steps.

If you build tables of rounded values, keys matter. Learn to check whether a key exists in a dict before you overwrite data.

Quick Comparison Table

Here is a simple recap of the main methods.


Method      Returns   Keeps .00   Best For
round()     float     no          math and quick values
format()    string    yes         labels and reports
f-string    string    yes         printing and logs
Decimal     Decimal   yes         money and exact rules

Pick round for numbers. Pick strings for display. Pick Decimal for money.

Conclusion

Rounding to 2 decimal places in Python is easy. Use round for numeric work. Use f-strings or format for clean text. Use Decimal when exactness matters.

Know the difference between a float and a string. That single choice prevents most bugs. Test your output with small examples before you ship code.

With these methods, your prices, scores, and reports will look sharp. You will also avoid the classic floating point traps. Happy coding.