Skip to main content

The module decimalfp provides a Decimal number type which can represent decimal numbers of (nearly) arbitrary magnitude and very large precision, i.e. with a very large number of fractional digits.

Usage

decimalfp.Decimal instances are created by giving a value (default: 0) and a precision (i.e the number of fractional digits, default: None).

If precision is given, it must be of type int and >= 0.

If value is given, it must either be a string, an instance of number.Integral, number.Rational (for example fractions.Fraction), decimal.Decimal or float or be convertable to a float or an int.

If a string is given as value, it must be a string in one of two formats:

[+|-]<int>[.<frac>][<e|E>[+|-]<exp>] or
[+|-].<frac>[<e|E>[+|-]<exp>].

The value is always adjusted to the given precision or the precision is calculated from the given value, if no precision is given.

When the given precision is lower than the precision of the given value, the result is rounded, according to the current default rounding mode (which itself defaults to ROUND_HALF_EVEN).

When no precision is given and the given value is a float or a numbers.Rational (but no Decimal), the Decimal constructor tries to convert value exactly. But this is done only up a fixed limit of fractional digits (imposed by the implementation, currently 65535). If value can not be represented as a Decimal within this limit, an exception is raised.

Decimal does not deal with infinity, division by 0 always raises a ZeroDivisionError. Likewise, infinite instances of type float or decimal.Decimal can not be converted to Decimal instances. The same is true for the 'not a number' instances of these types.

Computations

When importing decimalfp, its Decimal type is registered in Pythons numerical stack as subclass of number.Rational. It supports all operations defined for that base class and its instances can be mixed in computations with instances of all numeric types mentioned above.

All numerical operations give an exact result, i.e. they are not automatically constraint to the precision of the operands or to a number of significant digits (like the floating-point Decimal type from the standard module decimal). When the result can not exactly be represented by a Decimal instance within the limit of fractional digits, an instance of fractions.Fraction is returned.

Decimal supports rounding via the built-in function round using the same rounding mode as the float type by default (ROUND_HALF_EVEN in Python 3). In addition, via the method adjusted, a Decimal with a different precision can be derived, supporting all rounding modes defined by the standard library module decimal.

For more details see the documentation provided with the source distribution or here.

Release files for decimalfp 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decimalfp 0.13.0
File Size Uploaded
decimalfp-0.13.0.tar.gz 161.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for decimalfp 0.13.0
File Interpreter ABI Platform
decimalfp-0.13.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 285.2 kB

Release files / decimalfp-0.13.0.tar.gz

Download URL decimalfp-0.13.0.tar.gz
Size 161.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0ad4a99342c2a3e3ce975aa67e396bcd60bb0ae6c691e96e65fa07153c1c86bc
BLAKE2b-256 checksum
How to use checksums
896a6f4ca0b5278bd1b2bb7229cfb68ba868a2938a891861d784675770577830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / decimalfp-0.13.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL decimalfp-0.13.0-cp311-cp311-macosx_11_0_arm64.whl
Size 124.2 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9d8ba9b9efaaccf661b64a16b5015fc0015fd0813506e6666b4cff2a44d1cfb2
BLAKE2b-256 checksum
How to use checksums
9519c8bda317782d017ba5ce748a32bd50bde2fe164f41cc5f50f61e865da923
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.13.0 This release

2 release files

0.12.2

1 release file

0.12.1

1 release file

0.12.0

1 release file

0.11.4

1 release file

0.11.3

1 release file

0.11.2

1 release file

0.11.1

1 release file

0.11.0

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.14

1 release file

0.9.13

1 release file

0.9.12

1 release file

0.9.11

1 release file

0.9.10

0.9.9

1 release file

0.9.8

1 release file

0.9.7

1 release file

0.9.6

1 release file

0.9.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page