Rounds a measurement value and its uncertainty to a specified number of significant digits.
Project description
Rounds a measurement value and its uncertainty
Rounds a measurement value and its uncertainty to a specified number of significant digits.
First, the measurement uncertainty is rounded, by default to one significant digit unless this (first) significant digit is 1, in which case it is rounded to two significant digits. Rounding is always done upwards, that is, to a greater value unless rounding down is more reasonable (the second significant digit is zero), for example, 0.502 will be rounded to 0.5, not to 0.6. The number of significant digits can be explicitly specified, in which case the rounded value will always have as many significant digits as specified.
Next, the value itself is rounded so that it has the same number of decimal places as the measurement uncertainty.
Trailing zeros in these values are also considered significant, so a value of 0.50 indicates that we are confident that the second decimal place is zero. Writing 0.5 instead of 0.50 would suggest an unknown (unmeasured) value of the hundredths place, and such ambiguities are to be avoided.
The results are returned as a string to avoid potential formatting difficulties with numbers (which might lose trailing zeros). The current version, in accordance with the concept used in Python, always uses a dot as the decimal separator.
Examples:
>>> precise_rounding(123.45678, 0.0215)
('123.46', '0.03')
>>> precise_rounding(123.45678, 0.01009)
('123.457', '0.010')
>>> precise_rounding(123.4545, 0.07234, 2)
('123.455', '0.073')
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
File details
Details for the file precise_rounding-0.1.5.tar.gz.
File metadata
- Download URL: precise_rounding-0.1.5.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31b9ea268f0becc2ec5f8dde83a833e0d50338179fce302208427ebbafca46c8
|
|
| MD5 |
55d966aed9fe381c1f630a71dba9a3bd
|
|
| BLAKE2b-256 |
8d0c7f06bbea64ec34dfaceb090a122f1d6f6ca9f364d9fecb2f5afd8a990058
|