I've looked around and I cannot find an anwser to my question.
I need decimal formatting where the decimal can be different depending on the situation. For this situation I want to pass a variable containing the decimal value.
The values I'm getting from my pandas DataFrame are in this format 3.18e-06, which in this case needs to be turned into 8 decimals, e.g., 3.18123456
Can I either turn my pd DF into an 8 decimal based float64 or can i somehow convert 3.18e-06 into 8 decimals after grabbing it from my db?
Preferably I want to pass a variable containing the decimal for formatting. Something like:
decimal = 0.00000001
{0:.{decimal}f}".format(a)
EDIT:
In the end, none of the suggested options did it for me. Maybe I didn't phrase my question well enough. I'll share my solution here for anyone else who might need it.
ticksize is a variable which changes depending on the Binance Trading pair you're using, it comes in a format like: 0.00001 or 0.0000001.
async def get_precision(ticksize):
a = '{:.{prec}f}'.format(ticksize, prec=15)
regex = "..(\d+1).*"
try:
b = re.match(regex, str(a))[1]
precision = len(b)
return precision
except Exception as e:
print(f'An exception has occured on get_precision - {e}')
return False
# this function returns the length of ticksize starting from the first 0 after the dot.
# Now that we have our precision we can use a string format to get what we need.
last_buy = '{:.{prec}f}'.format(a, prec=precision)
#returns: Last purchase price for XRPBTC: 0.00001588