|
|
|
|
|
by Izkata
811 days ago
|
|
This is why Decimal exists: Python 3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> Decimal('100000.000000000017')
Decimal('100000.000000000017')
For example: >>> import json
>>> json.loads('{"a": 100000.000000000017}')
{'a': 100000.00000000001}
>>> json.loads('{"a": 100000.000000000017}', parse_float=Decimal)
{'a': Decimal('100000.000000000017')}
|
|
⸻
1. This is a bit on my mind lately as I discovered that LibraryThing’s sort by LoC classification seems to be broken so I exported my library (discovering that they export as ISO8859-1 with no option for UTF-8) and wrote a custom sorter for LOC classification codes for use in finally arranging the books on my shelves after my move last year.