← Back to Home

Python Round to 2 Decimal Places

Complete guide to rounding numbers to 2 decimals in Python

The round() Function

Python's built-in round() function is the simplest way to round numbers to 2 decimal places.

Basic Syntax

round(number, 2)

The 2 means "2 decimal places"

# Examples

round(3.14159, 2) # Returns: 3.14

round(12.567, 2) # Returns: 12.57

round(99.999, 2) # Returns: 100.0

Method 1: Built-in round() Function

# Basic usage

price = 12.3456

rounded_price = round(price, 2)

print(rounded_price) # Output: 12.35

⚠️ Important: Python uses "bankers' rounding" (round half to even). When exactly .5, it rounds to the nearest even number.

Method 2: Format as String with f-strings

value = 3.14159

formatted = f"{value:.2f}"

print(formatted) # Output: "3.14"

Note: This returns a string, not a number. Use this for display purposes.

Method 3: Decimal Module (High Precision)

from decimal import Decimal, ROUND_HALF_UP

value = Decimal('3.14159')

rounded = value.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)

print(rounded) # Output: 3.14

Use this for: Financial calculations requiring exact decimal precision

Complete Examples

# Example 1: Basic rounding

pi = 3.14159265

print(round(pi, 2)) # 3.14

# Example 2: Rounding in calculations

price = 19.99

tax_rate = 0.0875

total = round(price * (1 + tax_rate), 2)

print(total) # 21.74

# Example 3: Rounding list of numbers

numbers = [3.14159, 2.71828, 1.41421]

rounded = [round(n, 2) for n in numbers]

print(rounded) # [3.14, 2.72, 1.41]

Python's Bankers' Rounding

Python uses "round half to even" by default. When the digit is exactly 5, it rounds to the nearest even number:

round(2.5) # 2 (rounds to even)

round(3.5) # 4 (rounds to even)

round(4.5) # 4 (rounds to even)

round(5.5) # 6 (rounds to even)

This reduces bias in statistical calculations.

Quick Reference

🎯 Basic Rounding

round(number, 2)

📝 Format String

f"{value:.2f}"

💰 Financial

Use Decimal module

📊 Lists

[round(n,2) for n in list]