Skip to main content

A small, easy-to-use wrapper around Python's Decimal with configurable precision and rounding.

Project description

bignumx — Arbitrary-Precision Decimal Numbers for Python

bignumx is a tiny wrapper around Python’s built-in decimal.Decimal type.

It gives you:

  • Easy, consistent handling of big numbers (money, crypto, prices, etc.)
  • Configurable precision (DP) and rounding mode (RM)

Perfect when float is too imprecise and you want something safer but still easy to use.


Features

  • ✅ Arbitrary-precision decimal arithmetic
  • ✅ Global defaults for decimal places (DP) and rounding mode (RM)
  • ✅ Minimal, focused API
  • ✅ Works with str, int, float, Decimal, and Big values

Installation

If you’ve published this as a package:

pip install bignumx

Quick Start

from bignumx 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 bignumx import Big

print(0.1 + 0.2)        # 0.30000000000000004 (float)
print(Big("0.1") + Big("0.2"))  # 0.3 (Big)

Configuration

Big exposes two important global settings:

from bignumx 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.

Creating Big Numbers

from bignumx 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.

Arithmetic

The exact API here depends on how you implemented Big.

Below is a typical pattern using operator overloading.

Addition

x = Big("1.1")
y = Big("2.2")
print(x + y)      # -> 3.3

Subtraction

x = Big("5")
y = Big("2.5")
print(x - y)      # -> 2.5

Multiplication

x = Big("1.5")
y = Big("3")
print(x * y)      # -> 4.5

Division

Division respects Big.DP and Big.RM:

from bignumx 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)

License

MIT License

Copyright (c) 2026 Jack Dolan

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

bignumx-1.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bignumx-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file bignumx-1.0.0.tar.gz.

File metadata

  • Download URL: bignumx-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for bignumx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eebadca1566e7826a25d4ba94dde73048b07674d1dbbebcaff90d719d56f9b0d
MD5 fbed773fbaa5e8064453a605b155ec42
BLAKE2b-256 2093cf7974bee289fff13c038a3e907f2b7919ad9de2d97db7cbbc1c4d763d59

See more details on using hashes here.

File details

Details for the file bignumx-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bignumx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for bignumx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0cefe39febddcd4047b4bba428175aaa92cda942d2bfbb7c7b9408ebd6acf8ef
MD5 b20cad9cd3bebe6ee32dd826589b3fa8
BLAKE2b-256 859d1127908d5c87dbba88d02dc90bfd5954d7bd8925f61d2af62e7f2c192f26

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