Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json.loads converts decimal points to 'e' in python

Here is a response I am getting from server

[{"type":"bid","price":0.00000026,"amount":737.15054457,"tid":200001915,"timestamp":1516036570}]

I am trying to parse this string into JSON using

json_data = json.loads (req.text)

However when I try to read the 'price' using json_data[0]['price'] the output is 2.6e-07

I tried parsing data as json_data = json.loads (req.text, parse_float=Decimal) but still no difference.

like image 571
roxy boxy Avatar asked Jun 22 '26 19:06

roxy boxy


1 Answers

This is the way python shows floats

price = 0.00000026
print(price)

outputs: 2.6e-07 you can print it this way if you want to see it normal:

print('{0:.8f}'.format(price))

ouputs: 0.00000026

like image 183
Sharon Tourjeman Avatar answered Jun 24 '26 08:06

Sharon Tourjeman