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.2.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file saneround-0.1.2.tar.gz
.
File metadata
- Download URL: saneround-0.1.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f73442bd8a4f26f1f59a436f2991aaa479fd61dd2165a6827a5dada54aa74f8c |
|
MD5 | dfe984de9e77a8438c05e2f3aad2d093 |
|
BLAKE2b-256 | 938c9a6fc291e6e31a5a1c4e2222d6cd62279e58c8c3703aec1af55dabfc61ea |
File details
Details for the file saneround-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: saneround-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a17cebf09fcd6b32dcdfd9a9536f241722a3bb6a9aaaad9101aab34d77dd8dbd |
|
MD5 | b9d2bc00038480b2e12c49735d8958cf |
|
BLAKE2b-256 | f91f3652c8993414fe73b032a298100e51bf2d47118ceb8f05ce3ae5a4a2f6fb |