Reputation: 323
I tried different codes but I'm stuck in this. I get the output as a scientific notation when I convert the float to a precision of 8. I need to convert this to float back so I can do further calculations.
Code:
order_cummulativeQuoteQty = 0.0003400
order_executedQty = 8.97
ENTRY_PRICE = f"{order_cummulativeQuoteQty / order_executedQty:0.8f}"
CTP = ENTRY_PRICE
CTP += (CTP * 2.0 / 100)
print(CTP)
Error:
CTP += (CTP * 2 / 100)
TypeError: unsupported operand type(s) for /: 'str' and 'int'
How can I convert entry price back to float but it shouldn't be scientific notation again?
Upvotes: 0
Views: 545
Reputation: 117866
You should leave ENTRY_PRICE
as a float
for doing your further arithmetic, only convert to str
for printing purposes.
order_cummulativeQuoteQty = 0.0003400
order_executedQty = 8.97
ENTRY_PRICE = order_cummulativeQuoteQty / order_executedQty
CTP = ENTRY_PRICE
CTP += (CTP * 2.0 / 100)
print(f'{ENTRY_PRICE:0.8f}')
print(f'{CTP:0.8f}')
Output
0.00003790
0.00003866
Upvotes: 3