Round half away from zero.
Project description
Round half away from zero.
pip install round2
Since python's default round function uses 'bankers rounding', I made this small module that uses 'commercial rounding' instead. This means half is rounded up for positive numbers and down for negative numbers:
>>> from round2 import round2
>>> round2(1.5)
2
>>> round2(2.5)
3
>>> round2(-1.5)
-2
>>> round2(-2.5)
-3
>>> round2(2.5, decimals=1)
2.5
If decimals=0 (default), returns an int, otherwise a float, just like Python’s round function.
Implemented in Cython with type hinting in Python.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
round2-0.0.4.tar.gz
(24.0 kB
view hashes)
Built Distribution
Close
Hashes for round2-0.0.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f509c5fc5a7355c2ec6906b9babc6ae9fcc240fb6a25e162c73090e3146a0c6e |
|
MD5 | 5f56b73b81f9b8caa0aa881cc8d1dc41 |
|
BLAKE2b-256 | d03348af2bd0ed8dc9d90256a2fbe2b5aa042e6ade8ebfc7fb015c376a0018e7 |