-1

I want to convert numbers from the following format in a text file: 3.0236E+01 to a plain decimal number in python and add them to a new text file. Is there a way to do this?

newbie
  • 338
  • 2
  • 12

3 Answers3

1

Using

"{:f}".format(3.0236E+01)
Clément
  • 993
  • 6
  • 18
0

Use numpy.around(num,decimals=3) after reading the numbers from the text file

Arpit
  • 378
  • 1
  • 10
0

Use float to convert it from scientific notation to the full written number: float('scientific-notation-string')

float('3.0236E+01')
>>> 30.236
with open('file-with-scientific-notations') as fd:
    parsed_numbers = [float(scientific_notation) for scientific_notation in fd.readlines()
with open('dest', 'w') as fd:
    for num in parsed_numbers:
        fd.write(f'{num}\n')
Or Y
  • 1,923
  • 1
  • 15