Reputation: 1201
i am using python requests to convert usd value to btc.
res = requests.get("https://blockchain.info/tobtc?currency=USD&value="+str(float(rawUSD)))
res.json() = 7.7e-07
res.text = 0.00000077
Getting '0.00000077' in res.text which a <class:str>
type so converting it again to float gives me this.
float('0.00000077') = 7.7e-07
but i want it as 0.00000077 so i can use it in later calculation. i know both 0.00000077 and 7.7e-07 are same and python treats them as float but i am trying to save the end value in db and i cant save it as 7.7e-07.
how can i do so?
Upvotes: 0
Views: 207
Reputation: 1086
You can make use of python's decimal module.
from decimal import Decimal
print("{:.2e}".format(Decimal(res.text)))
Upvotes: 1