Skip to main content

Python package providing sane round() instead of official insane round().

Project description

saneround

Python package providing sane round() instead of official insane round().

Quick start

Install this package using pip:

pip install saneround

Import saneround package as sr and use sr.round(number: Union[int, float], ndigits: int = 0) -> float:

>>> import saneround as sr
>>> sr.round(0.4)
0.0
>>> sr.round(0.5)
1.0
>>> sr.round(1.4)
1.0
>>> sr.round(1.5)
2.0
>>> sr.round(-0.4)
0.0
>>> sr.round(-0.5)
-1.0
>>> sr.round(-1.4)
-1.0
>>> sr.round(-1.5)
-2.0
>>> sr.round(1234.567, 2)
1234.57
>>> sr.round(1234.576, -2)
1200.0

Comparison with others

There are some similar packages:

  • builtin
  • round2 (0.0.4)
  • math-round (0.0.3.post1)
  • math-round-af (1.0.3)

Comparison results are here:

saneround builtin round2 math-round math-round-af
round(0.5) 1.0 0 1 1 1.0
round(1.5) 2.0 2 2 2 2.0
round(-0.5) -1.0 0 -1 0 -1.0
round(-1.5) -2.0 -2 -2 -1 -2.0
round(0.49999999999999994) 0.0 0 0 1 0.0
round(1.255, 2) 1.26 1.25 1.25 1.25 1.25
round(123456.78, -2) 123500.0 123500.0 nan 123500.0 Error
round(0.12345, -1) 0.0 0.0 nan 0.0 Error
round(42.0, 308) 42.0 42.0 nan Error Error
round(0.42, 2**30) 0.42 0.42 nan (too late) (too late)
round(2.5e20, -20) 3e+20 2e+20 nan 3e+20 Error
round(0.5, 23) 0.5 0.5 -1.0717247280990649e-08 0.49999999999999994 0.49999999999999994

saneround is very robust.

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

saneround-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

saneround-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file saneround-0.1.0.tar.gz.

File metadata

  • Download URL: saneround-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.4

File hashes

Hashes for saneround-0.1.0.tar.gz
Algorithm Hash digest
SHA256 13a923c88d623fb7b1ec4315151d6e3052e96df3e2bcf83d6c1de288472eee7f
MD5 67c1a601c9b492356de928cf3aed0034
BLAKE2b-256 a584fa94abe6aa0ae9a61dda560196464811bf1c690f676bd87bce55bfa052d5

See more details on using hashes here.

File details

Details for the file saneround-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: saneround-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.4

File hashes

Hashes for saneround-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8cd1824aa4697d30302e116d73f6840aeb403035bb17886d9dd65da57ac4a3a
MD5 6c530b2412e631616d1cfd977ab02e7e
BLAKE2b-256 13cf659e9e23b9b9d98b17d49d5f5a7f0e198b90abcf93d991886a072b174164

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