python浮点数的描述_Python中浮点数int()使用技巧问题

74d287a32af47a36320dfb8657659611.png

int()描述如下:

int(x=0) -> int or long

int(x, base=10) -> int or long

Convert a number or string to an integer, or return 0 if no arguments

are given. If x is floating point, the conversion truncates towards

zero. If x is outside the integer range, the function returns a long

instead.

If x is not a number or if base is given, then x must be a string or

Unicode object representing an integer literal in the given base. The

literal can be preceded by '+' or '-' and be surrounded by whitespace.

The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to

interpret the base from the string as an integer literal.

上述提出如果是浮点数,就截去小数。为什么我截图的这个例子结果跟我想象的不一样呢?

谢谢大家帮我解答!

Cpython中的Float底层是靠double (64 bit)来实现的.

根据IEEE 754的标准,double就52位的mantissa,所以你那N多9超过了能无损代表的整数范围了。

下面是临街点,正整数里比2 ** 53小的都没问题>>> 2 ** 53

9007199254740992

>>> int(9007199254740992.1)

9007199254740992

>>> int(9007199254740993.1)

9007199254740994

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd18539.html

相关文章 Recommend

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值