Skip to main content

Decimal compatability with float

Project description

Decimal compatability with float

  • Free software: BSD license


Implicit float-to-Decimal coercion for arithmetic operations.

Instead of this:

>>> from decimal import Decimal
>>> Decimal(12.0) * 0.5
TypeError: unsupported operand type(s) for *: 'Decimal' and 'float'

Use FDecimal:

>>> from fdecimal import FDecimal
>>> FDecimal(12.0) * 0.5

As you can see it only solves part of the problem - the result still can’t be added with a float value without explicit type coercion, but it solves some problems where (1) its not clear what type the other value will be, (2) you don’t want to add code explicitly handling that coercion, and (3) an arithmetic surprises due to working with different numeric types are acceptable.


  • Missing operations, including mod, floor div
  • Python 3 support
  • Return FDecimal objects rather than Decimal objects
  • Allow cdecimal swap-in


0.1.0 (2016-01-14)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fdecimal, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size fdecimal-0.1.0.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page