Rounders

0.2.0 · active · verified Thu Apr 16

The `rounders` package extends Python's built-in `round` function, providing a comprehensive collection of decimal rounding functionalities. It offers drop-in replacements for `round` that support thirteen different rounding modes beyond Python's default Banker's rounding, as well as functionality for rounding to a specified number of significant figures. The current version is 0.2.0, released on June 9, 2024, with an active development status.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates importing `round` with custom modes and `round_to_figures` for significant digit rounding. It highlights the behavior of `TIES_TO_AWAY` versus the default `TIES_TO_EVEN` (Banker's rounding) and `TO_MINUS`.

from rounders import round, TIES_TO_AWAY, TO_MINUS, round_to_figures

# Using a different rounding mode (TIES_TO_AWAY - commonly taught in schools)
result_away = round(2.5, mode=TIES_TO_AWAY)
print(f"round(2.5, mode=TIES_TO_AWAY): {result_away}")

# Rounding towards negative infinity (like math.floor)
result_tominus = round(2.97, 1, mode=TO_MINUS)
print(f"round(2.97, 1, mode=TO_MINUS): {result_tominus}")

# Rounding to significant figures
result_figures = round_to_figures(12345.67, 3)
print(f"round_to_figures(12345.67, 3): {result_figures}")

# Using default mode (TIES_TO_EVEN / Banker's Rounding)
result_default = round(2.5)
print(f"round(2.5) [default TIES_TO_EVEN]: {result_default}")

view raw JSON →