I have a float number stored as scientific notation in a tuple:
correlation = (1,1.1884423896339773e-06)
I want to reformat that float (correlation[1]
) into the following format, to be plotted as a string in a plot:
1.19 * 10^-6 # '-6' should be in superscript actually here
However, I am getting an SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape
lsF = str(correlation[1])
ePos = lsF.find("e")
if (ePos):
base = float(lsF[:ePos])
exponent = int(lsF[ePos+1:])
else:
base = float(lsF)
exponent = 0
print(round(base, 2), " * 10", eval(r'"\u00b' + str(exponent) + '"'), sep="")
When my exponent
is positive, this works well.