Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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
  • Allow cdecimal swap-in


  • Return FDecimal objects rather than Decimal objects


0.2.0 (2016-01-14)

  • Add support for returning FDecimal objects from operations

0.1.0 (2016-01-14)

  • First release on PyPI.

Release History

This version
History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(5.7 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Jan 14, 2016
(6.7 kB) Copy SHA256 Hash SHA256
Source None Jan 14, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting