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 details)

Uploaded Source

Built Distribution

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

Uploaded CPython 3.9 Windows x86-64

File details

Details for the file round2-0.0.4.tar.gz.

File metadata

  • Download URL: round2-0.0.4.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for round2-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9b5f43861ad31db9a2a26dfb50b8591ea5524984e6f58fc59c2a4e5c7dde9a2a
MD5 3c31d778f2f024dc1c3e1afcc4296e5f
BLAKE2b-256 786d383882b83f3224168c69dc54981d83ac78db17548bd197c639a4969d23a3

See more details on using hashes here.

File details

Details for the file round2-0.0.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: round2-0.0.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for round2-0.0.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f509c5fc5a7355c2ec6906b9babc6ae9fcc240fb6a25e162c73090e3146a0c6e
MD5 5f56b73b81f9b8caa0aa881cc8d1dc41
BLAKE2b-256 d03348af2bd0ed8dc9d90256a2fbe2b5aa042e6ade8ebfc7fb015c376a0018e7

See more details on using hashes here.

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