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.
Metadata
Release files for saneround 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| saneround-0.1.2.tar.gz | 3.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| saneround-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.8 kB
Release files / saneround-0.1.2.tar.gz
| Download URL | saneround-0.1.2.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f73442bd8a4f26f1f59a436f2991aaa479fd61dd2165a6827a5dada54aa74f8c
|
|
BLAKE2b-256 checksum How to use checksums |
938c9a6fc291e6e31a5a1c4e2222d6cd62279e58c8c3703aec1af55dabfc61ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.4
|
Release files / saneround-0.1.2-py3-none-any.whl
| Download URL | saneround-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a17cebf09fcd6b32dcdfd9a9536f241722a3bb6a9aaaad9101aab34d77dd8dbd
|
|
BLAKE2b-256 checksum How to use checksums |
f91f3652c8993414fe73b032a298100e51bf2d47118ceb8f05ce3ae5a4a2f6fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.4
|