sigfig - Scientific Rounding

1.3.19 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →