Code shows results when run interactively, but not when run from a shell

后端 未结 1 390
忘掉有多难
忘掉有多难 2021-01-25 02:47

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         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 03:10

    The interactive interpreter auto-echoes the results of any expression that doesn't return None. In a script you need to explicitly print the results you want to see:

    print format_e(Decimal('40800000000.00000000000000'))
    print format_e(Decimal('40000000000.00000000000000'))
    print format_e(Decimal('40812300000.00000000000000'))
    

    0 讨论(0)
提交回复
热议问题