Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

.round

Rounds floating-point expression values to a specified number of decimal places. The default half_to_even mode resolves ties by choosing the nearest even value.

How it works

Expr.round returns an expression that rounds floating-point values to a chosen number of decimal places. It uses the selected strategy for tie handling or, with to_zero, truncates toward zero.

Syntax

Expr.round(decimals: int = 0, mode: RoundMode = 'half_to_even') → Expr

Parameters

NameTypeDescription
decimalsint = 0Number of decimals to round by.
modeRoundMode = 'half_to_even'Rounding strategy; one of half_to_even, half_away_from_zero, or to_zero.

Returns

Expr

Key points

  • The expression rounds floating-point values to the number of decimal places specified by decimals.
  • The result has no more than the requested number of decimal places; zero decimals produces whole-number precision.
  • The mode parameter selects how rounding is performed.
  • Both half_to_even and half_away_from_zero first choose the nearest rounded value.
  • half_to_even resolves exact halfway cases by selecting the even result.
  • half_away_from_zero resolves exact halfway cases in the direction away from zero.
  • to_zero discards the remaining fractional portion toward zero at the requested precision.

Common mistakes

  • Choose to_zero when truncation toward zero is intended; the documentation identifies that behavior as equivalent to truncate().

Example: Round an expression

import polars as pl

df = pl.DataFrame({"price": [1.234, 2.345, 2.5]})
result = df.select(pl.col("price").round(2))
print(result)

Rounds the selected floating-point column to two decimal places using the default half-to-even strategy.

When to use it

Control decimal precision

Normalize measured or monetary-like floating-point columns before display or downstream calculations.

Choose a rounding policy

Apply predictable tie-breaking when aggregating or presenting numeric results.

Truncate toward zero

Remove fractional precision without nearest-value rounding.

Interview questions

QWhat does Expr.round do, and what is its default precision?

It rounds the underlying floating-point data by the requested number of decimal digits and returns an Expr. With decimals=0, values are rounded to whole-number precision.

Follow-up: What happens for an exact tie under the default mode? The nearest even rounded value is selected, such as 0.5 to 0 and 1.5 to 2.

QHow does half_to_even differ from half_away_from_zero?

half_to_even rounds to the nearest value and resolves ties using the nearest even value. This is the default strategy and is also called banker’s rounding.

Follow-up: Why use it by default? The documentation says it tends to minimize cumulative rounding bias.

QWhen should the to_zero mode be used?

The to_zero mode always truncates toward zero, discarding fractional digits beyond the requested precision. Unlike half-based modes, it is not only a tie-breaking rule; it always determines the chosen rounded value.

Follow-up: Which related operation has equivalent behavior? The documentation states that Expr.round with to_zero is equivalent to truncate().

  • polars.Series.round
  • polars.Expr.truncate
  • polars.Expr.dt.round

Source: polars.Expr.round. Checked 2026-10-15.