3 ms·
For Python, I prefer decimal.Decimal[1]. When you serialize, you can either convert it to a string (and then have your deserializer know the field type and auto
by spamizbad 5y ago
For Python, I prefer decimal.Decimal[1]. When you serialize, you can either convert it to a string (and then have your deserializer know the field type and automatically encode it back into a decimal) OR just agree all numeric values can only be ints or decimals. You can pass parse_float=decimal.Decimal to json.loads[2] to make this easier.
My most obnoxious and spicy programming take is that ints an decimals should be built-in and floats should require imports. I understand why though: Decimal encoding isn't anywhere near as standardized as other numeric types like integers or floating-point numbers.
[1] https://docs.python.org/3/library/decimal.html https://docs.python.org/3/library/decimal.html
[2] https://docs.python.org/3/library/json.html https://docs.python.org/3/library/json.html
- dragonwriter 5y ago> My most obnoxious and spicy programming take is that ints an decimals should be built-in and floats should require imports I don't care about making inexact numbers require imports, but the most natural literal formats should produce exact integers, decimals, and/or rationals.