I have a file that has thousands of values in scientific notation up to 12 digits after the decimal. I am trying to use Python to truncate all values in this file to 6 digits after the decimal and overwrite the existing file. Can I just use the decimal package to do this?
from decimal import Decimal as D, ROUND_DOWN
with open("foo.txt", "a") as f:
f.D('*').quantize(D('0.000001'), rounding=ROUND_DOWN)
f.write("foo.txt")