The following code prints decimals of various precisions, but reverts to scientific notation past 7 places. I need to display a string width of at least 8 places in my UI.
How do I get a stringified decimal with 8 places of precision?
from decimal import *
getcontext().prec = 8 # set precision to 8 decimal points.
getcontext().rounding = "ROUND_DOWN" # alway round down
# stringified zero of various precisions
zw = ['0', '0.0', '0.00', '0.000000', '.00000000', '0.00000000', '0.000000000000']
for n in range(0,len(zw)):
zstr = zw[n] # stringified zero
zdec = Decimal(zstr) # decimalized zero
print (zstr, ":", zdec) # compare stringified and decimalized zero