Skip to main content

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


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)

Uploaded Source

Built Distribution

round2-0.0.4-cp39-cp39-win_amd64.whl (14.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page