为了账号安全,请及时绑定邮箱和手机立即绑定

Python 转换皮秒和飞秒没有以秒为单位给出正确的时间

Python 转换皮秒和飞秒没有以秒为单位给出正确的时间

潇潇雨雨 2022-11-29 17:05:08
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条经验 获得超3个赞

浮点数无法用任何编程语言准确表示,原因很简单,因为浮点数的数量是无限的。但是,可能对您有帮助的是DecimalClarification on the Decimal type in Python

文档:https ://docs.python.org/3.8/library/decimal.html


查看完整回答
反对 回复 2022-11-29
  • 1 回答
  • 0 关注
  • 120 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信