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.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: saneround-0.1.1.tar.gz
  • Upload date:
  • Size: 3.2 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.1.tar.gz
Algorithm Hash digest
SHA256 751f4531381558a4339110514ed27f3ff40e0612d3cc32a5a61defc5e4e7c054
MD5 5f4cbb77996041749aefb5b67137d973
BLAKE2b-256 dfaf4414280ed8628210e32475fd57281d4163555d948d4fc6bc58e9ea9dd1a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: saneround-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07bda81d92aa1709eefd183e014a216b6da0f9419a56f7a5a0f7bcbac5901253
MD5 57dae925f94b01ba814b732042e12163
BLAKE2b-256 5ee00e54c9cf20eb72a5fe1333c7ad13c05012006090cff861ad16e04fef5510

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