2016-09-23 48 views
0

我在嘗試將我的「def定價(問題)」函數的結果轉換爲十進制值而不是科學時遇到了問題。如何在Python中將科學數字格式化爲十進制格式?

我試圖將結果轉換爲字符串,但沒有奏效,我無法看到格式化pricex變量的位置。

任何幫助深表感謝

Code

enter image description here Result

enter image description here

+0

您應該在問題中發佈您的代碼。您可以通過突出顯示並按下CTRL + k來格式化該問題 –

+0

此問題已在SO上得到解答:[將科學表示法轉換爲十進制 - Python](http://stackoverflow.com/questions/16962512/convert-scientific-notation-到十進制蟒) – soohoonigan

回答

1

您需要使用格式化字符串。

>>> import math 
>>> print(math.pi) 
3.141592653589793 
>>> print("{:.2f}".format(math.pi)) 
3.14 
相關問題