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.
- Host: GitHub
- URL: https://github.com/weaming/patch-json-float
- Owner: weaming
- Created: 2019-10-15T05:11:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-21T08:28:26.000Z (over 6 years ago)
- Last Synced: 2025-09-25T11:45:16.728Z (9 months ago)
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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']))
(, , )
```