json.dumps outputs small float or decimal values using scientific notation, which is unacceptable to the json-rpc application this output is sent to.
>>> import json
>>> json.dumps({"x": 0.0000001})
'{"x": 1e-07}'
I want this output instead:
'{"x": 0.0000001}'
It would be ideal to avoid introducing additional dependencies.
found somewhere on the internet
after this
One way to format
is to steal
Decimal
's "f" formatter. It's the only easy way I've found that avoids both cropping problems and exponents, but it's not space efficient.To use it you can make an encoder that "decimalize"s the input
or, of course, you could move the decimalization out into a function and call that before
json.dumps
.That's how I would do it, even if it's a lame method.