An open API service indexing awesome lists of open source software.

https://github.com/weaming/patch-json-float

Patch builtin's float to kill gap between float and Decimal.
https://github.com/weaming/patch-json-float

Last synced: 18 days ago
JSON representation

Patch builtin's float to kill gap between float and Decimal.

Awesome Lists containing this project

README

          

# Patch Python `float`

A wrapper `Float` for `float` which will convert `float` to `decimal.Decimal` for every math calculation operations. No more `0.1 + 0.2 != 0.3` :smile:

## Example

```python
>>> import json
>>> from decimal import Decimal
>>> from patch_float import builtins_float, Float, patch_json_loads, patch_float_all
>>> (builtins_float, float, Float)
(, , )
>>> (type(0.1), type(float(0.1)), type(json.loads('{"a": 0.1}')['a']))
(, , )
>>> patch_float_all()
==> WARNING: patched builtins float
>>> (type(0.1), type(float(0.1)), type(json.loads('{"a": 0.1}')['a']))
(, , )
```