I'm converting from all units of time to seconds and for some reason with the smaller units of time (picoseconds and femtoseconds), i'm getting (femtoseconds): 0.00000000000000100000000000000007770539987666107923830718560119501514549256171449087560176849365234375 instead of 0.000000000000001.有誰知道為什么?days = int(input("Enter the amount of days: ")) * 24 * 60 * 60hours = int(input("Enter the amount of hours: ")) * 60 * 60minutes = int(input("Enter the amount of minutes: ")) * 60ms = int(input("Enter the amount of milliseconds: ")) * (10 ** -3)mcs = int(input("Enter the amount of microseconds: ")) * (10 ** -6)ns = int(input("Enter the amount of nanoseconds: ")) * (10 ** -9)ps = int(input("Enter the amount of picoseconds: ")) * (10 ** -12)fs = int(input("Enter the amount of femtoseconds: ")) * (10 ** -15)s = days + hours + minutes + ms + mcs + ns + ps + fsprint("The amount of seconds is:", "{0:.50}".format(s))
1 回答

手掌心
TA貢獻1942條經(jīng)驗 獲得超3個贊
浮點數(shù)無法用任何編程語言準確表示,原因很簡單,因為浮點數(shù)的數(shù)量是無限的。但是,可能對您有幫助的是Decimal
:Clarification on the Decimal type in Python
文檔:https ://docs.python.org/3.8/library/decimal.html
添加回答
舉報
0/150
提交
取消