round(x,n)
x : Input number . print(round(12.34567)) # 12
print(round(-12.34567)) # -12
print(round(12)) # 12
print(round(-12)) # -12
print(round(12.34567,2)) # 12.35
print(round(-12.34567,3)) # -12.346
The `round()` function in Python is used to round a floating-point number to a specified number of decimal places. This function is commonly applied in financial calculations, formatting outputs, and data analysis.print(round(3.675,2)) # 3.67
Rounding to Nearest hundreds, thousands:print(round(1245, -2)) # Output: 1200
print(round(1245, -3)) # Output: 1000
print(round(1295, -2)) # Output: 1300
print(round(1745, -3)) # Output: 2000
Rounding Floats in Lists:values = [1.5678, 2.456, 3.14159]
rounded_values = [round(v, 2) for v in values]
print(rounded_values) # Output: [1.57, 2.46, 3.14]
Use Case: Financial Calculations: In banking applications, rounding is critical to ensure monetary precision:amount = round(49.56789, 2) # Output: 49.57
print(round(12.34567)) # Output: 12
print(round(-12.34567)) # Output: -12
print(round(12.34567, 2)) # Output: 12.35
print(round(-12.34567, 3)) # Output: -12.346
print(round(3.675, 2)) # Expected: 3.68, Actual: 3.67
from decimal import Decimal, ROUND_HALF_UP
value = Decimal('3.675').quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
print(value) # Output: 3.68
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.