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.3.tar.gz
(23.1 kB
view hashes)
Built Distribution
Close
Hashes for round2-0.0.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd99ea6abe5a57595f67c6dae205eae1d77ca7e9d11cb37738ee07d879bb9085 |
|
MD5 | e8eae13db535450a6a34f7a4bbfcd8bf |
|
BLAKE2b-256 | a06cf657a4a6ce403e5bdd87636a0ba556bc6b43b4d35e4fae18e9098b58d8d0 |