I borrowed this little scientific notation script from another poster: Display a decimal in scientific notation.
def format_e(n):
a = '%E' % n
return a.split('E')[0].rstrip('0').rstrip('.') + 'E' + a.split('E')[1]
format_e(Decimal('40800000000.00000000000000'))
# '4.08E+10'
format_e(Decimal('40000000000.00000000000000'))
# '4E+10'
format_e(Decimal('40812300000.00000000000000'))
The function works fine when manipulated as module from the Terminal or the Python Shell. However, when ran like 'python Converter.py' it terminates immediately without returning any of the three examples above.