Registry / data / sigfig

sigfig

JSON →
library1.3.19pypypi✓ verified 90d ago

sigfig is a Python library (current version 1.3.19) designed for precise rounding of numbers based on significant figures, decimal places, or uncertainty. It also provides versatile formatting options and can interpret various numeric input types (e.g., strings, floats, Decimals). The library aims to provide expected rounding results in scientific and engineering contexts, often differing from Python's built-in `round()` function. It is actively maintained with releases as recent as March 2025.

pip install sigfig
INSTALL
IMPORT
SIG · SIGFIG
S
sigfig
datapythonv1.3.19
Install
1.6s avg
Import
40ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.3.19 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.044s · 18.1MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.037s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

round
✓ from sigfig import round
✗ round(0.25, 1)
The `sigfig.round` function provides different (often more scientifically accurate) rounding behavior than Python's built-in `round()`, especially concerning decimal places and significant figures. The built-in `round(0.25, 1)` yields `0.2`, while `sigfig.round(0.25, decimals=1)` yields `0.3`.

This quickstart demonstrates how to import `sigfig.round` and use it for common rounding operations: by significant figures, by decimal places, and by uncertainty. It also highlights the recommendation to pass numbers as strings to maintain precision.

from sigfig import round # Round to 4 significant figures result_sigfigs = round('123.456', sigfigs=4) print(f"Rounded to significant figures: {result_sigfigs}") # Round to 2 decimal places result_decimals = round('3.14159', decimals=2) print(f"Rounded to decimal places: {result_decimals}") # Round by uncertainty result_uncertainty = round('3.14159', uncertainty=2) print(f"Rounded by uncertainty: {result_uncertainty}")
Debug
Known issues
gotchaPython's native float type can lead to precision loss, especially with trailing zeros (e.g., `10.0` might internally be `10.0` with 2 sigfigs, not `10.00` with 3). This can cause `sigfig` to misinterpret the intended precision.
fix
Pass numbers to `sigfig.round()` as strings (e.g., `'10.00'`) or `decimal.Decimal` objects when precise control over significant figures and trailing zeros is critical.
affects: All versions
gotchaImporting `from sigfig import round` directly overwrites the built-in `round()` function. This can lead to unexpected behavior if other parts of your code rely on the standard `round()` behavior.
fix
Import `sigfig` with an alias (e.g., `import sigfig as sf`) and call its functions explicitly (e.g., `sf.round()`) to avoid conflicts.
affects: All versions
gotchaThe library may issue a `UserWarning` if you request more significant figures than the input number inherently possesses, indicating potential 'invented numbers'.
fix
Ensure the input number has sufficient precision (e.g., by providing it as a string with enough digits, like `'1.000'`). If you intentionally want to format a number to a minimum number of significant figures, you can suppress the warning with `warn=False` (e.g., `round(1, sigfigs=3, warn=False)`).
affects: All versions
Errors
Common errors & fixes
UserWarning: warning: X significant figures requested from number with only Y significant figures
You are attempting to round a number to more significant figures than it inherently possesses or than `sigfig` can infer from its type. For example, passing the integer `1` and requesting `sigfigs=3`.
fix
Provide the number with sufficient precision (e.g., as a string `'1.00'`). Alternatively, if the intent is to enforce a minimum number of significant figures, suppress the warning: `from sigfig import round; round(1, sigfigs=3, warn=False)`.
Incorrect rounding or significant figure count for numbers with trailing zeros (e.g., 10.0, 1200)
Python's `float` type often discards trailing zeros that are significant in scientific notation (e.g., `float('10.00')` might be `10.0`). When `sigfig` receives such a float, it loses the original precision information.
fix
Always pass numbers as strings (e.g., `'10.00'`, `'1200.'`) or `decimal.Decimal` objects to `sigfig.round()` to preserve all significant digits, including trailing zeros. Example: `from sigfig import round; round('10.00', sigfigs=3)`.
Upgrade
Version history
1.3.19latest on PyPI · released Mar 10, 2025
Audit
Dependencies
sortedcontainersrequiredUsed for internal data structures and is listed as a dependency for manual installations.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
sigfig — pip install sigfig · libregistry