
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
bignum
Advanced tools
A small, easy-to-use wrapper around Python's Decimal with configurable precision and rounding.
Bignum is a tiny wrapper around Python’s built-in decimal.Decimal type.
It gives you:
DP) and rounding mode (RM)Perfect when float is too imprecise and you want something safer but still easy to use.
DP) and rounding mode (RM)str, int, float, Decimal, and Big valuesIf you’ve published this as a package:
pip install bignum
from bignum import Big
# Basic construction
a = Big("0.1")
b = Big("0.2")
# Addition
c = a + b
print(c) # -> 0.3
# Or using methods, if you added them:
# c = a.add(b)
# Multiplication
d = Big("1.23") * Big("4")
print(d) # -> 4.92
Because Big uses Decimal under the hood, you don’t get the usual floating-point surprises:
from bignum import Big
print(0.1 + 0.2) # 0.30000000000000004 (float)
print(Big("0.1") + Big("0.2")) # 0.3 (Big)
Big exposes two important global settings:
from bignum import Big
# Maximum decimal places for division, sqrt, etc.
Big.DP = 20 # default: 20
# Rounding mode (like big.js)
# 0: ROUND_DOWN
# 1: ROUND_HALF_UP (default)
# 2: ROUND_HALF_EVEN
# 3: ROUND_UP
Big.RM = 1
Internally, these map to decimal’s rounding modes via _ROUND_MAP.
You can also use decimal.localcontext() for temporary precision overrides inside your own code, but for most use cases, setting Big.DP and Big.RM is enough.
from bignum import Big
from decimal import Decimal
Big("1.2345") # from string
Big(12345) # from int
Big(1.2345) # from float (not recommended for exact finance values)
Big(Decimal("1.2345"))# from Decimal
Big(Big("1.2345")) # from another Big
Under the hood, the constructor converts the value to a Decimal and stores it as self._d.
The exact API here depends on how you implemented Big.
Below is a typical pattern using operator overloading.
x = Big("1.1")
y = Big("2.2")
print(x + y) # -> 3.3
x = Big("5")
y = Big("2.5")
print(x - y) # -> 2.5
x = Big("1.5")
y = Big("3")
print(x * y) # -> 4.5
Division respects Big.DP and Big.RM:
from bignum import Big
Big.DP = 10
Big.RM = 1 # ROUND_HALF_UP
x = Big("1")
y = Big("3")
print(x / y) # -> 0.3333333333 (10 decimal places)
MIT License
Copyright (c) 2025 kent-griffin
FAQs
A small, easy-to-use wrapper around Python's Decimal with configurable precision and rounding.
We found that bignum demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.