Python's decimal.Decimal
automatically converts the following number (7 zeros and a one, after the decimal point) into scientific notation:
d = decimal.Decimal('0.00000001')
import simplejson; simplejson.dumps({"val": d})
'{"val": 1E-8}' #what do I do so the output is '{"val": 0.00000001}' (float, not string)?
How could I change this so that the JSON output is 0.00000001
instead of 1E-8
?
I cannot use solutions that employ format
since it changes the type to string
, but I need to preserve to type to decimal (or at least float).
Some context: The output is sent as JSON response of an API, and the client expects floats in decimal notation. Converting it to scientific notation OR changing the type to string breaks the contract with client.