我有一个Decimal('3.9')对象的一部分,并希望将其编码为一个看起来像的JSON字符串{'x': 3.9}.我不关心客户端的精度,所以浮动很好.
Decimal('3.9')
{'x': 3.9}
是否有一种很好的方法来序列化这个?JSONDecoder不接受Decimal对象,并且事先转换为float会产生{'x': 3.8999999999999999}错误,并且会大大浪费带宽.
{'x': 3.8999999999999999}
python floating-point json decimal
decimal ×1
floating-point ×1
json ×1
python ×1