Skip to main content

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

precise_rounding-0.2.1.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file precise_rounding-0.2.1.tar.gz.

File metadata

  • Download URL: precise_rounding-0.2.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for precise_rounding-0.2.1.tar.gz
Algorithm Hash digest
SHA256 be199df84705263a0abf96ec6340baf4cc246d3c0072cf94cb68b881096b3601
MD5 d29f1c8f0aa23c4a8b95a37f619c18bf
BLAKE2b-256 03ff84db2c0a022725f357bf3250d454fcf9c41a3aa9343e2f3c0e4ecc8f7f01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page