浮在地板上 [英] Taking the floor of a float
本文介绍了浮在地板上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了两种使用Python发言的方法:
I have found two ways of taking floors in Python:
3.1415 // 1
和
import math
math.floor(3.1415)
第一种方法的问题是它返回一个浮点数(即3.0
).第二种方法感觉笨拙且时间太长.
The problem with the first approach is that it return a float (namely 3.0
). The second approach feels clumsy and too long.
是否有其他解决方案可以在Python中使用地板?
Are there alternative solutions for taking floors in Python?
推荐答案
只要您的数字为正,就可以简单地转换为int
以四舍五入到下一个整数:
As long as your numbers are positive, you can simply convert to an int
to round down to the next integer:
>>> int(3.1415)
3
对于负整数,这将四舍五入.
For negative integers, this will round up, though.
这篇关于浮在地板上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文