iteround
raw JSON → 1.0.4 verified Fri May 01 auth: no python
A Python library for rounding iterables (lists, arrays, sets, etc.) while preserving the total sum of the original values. Version 1.0.4 is stable with no recent updates; maintained on GitHub.
pip install iteround Common errors
error NameError: name 'iteround' is not defined ↓
cause Attempting to call `iteround(...)` directly without importing the function.
fix
Use
from iteround import safe_round then call safe_round(...). error TypeError: safe_round() got an unexpected keyword argument 'precision' ↓
cause Using the wrong parameter name; the correct parameter is `places` not `precision`.
fix
Use
safe_round(values, places=2) instead of safe_round(values, precision=2). Warnings
gotcha The function name is `safe_round`, not `iteround` or `round_iterable`. Using a wrong import will cause NameError. ↓
fix Use `from iteround import safe_round`.
gotcha The rounding algorithm adjusts some values to preserve the sum, so individual values may not round naively. This is intentional but can be surprising if you expect standard rounding. ↓
fix Understand that `safe_round` trades off per-element rounding accuracy for total sum preservation.
deprecated The `topline` parameter in `safe_round` was added in 1.0.3 but may be renamed in future versions. Check the documentation for the latest signature. ↓
fix Always pass `topline` as a keyword argument to avoid breakage if the parameter order changes.
Imports
- safe_round
from iteround import safe_round
Quickstart
from iteround import safe_round
values = [1.5, 2.5, 3.5]
rounded = safe_round(values, places=0)
print(rounded)
# Output: [2, 2, 4] (sum remains 7, same as original)