Taking the floor of a float

前端 未结 6 534
礼貌的吻别
礼貌的吻别 2021-02-01 13:21

I have found two ways of taking floors in Python:

3.1415 // 1

and

import math
math.floor(3.1415)

The problem

6条回答
  •  无人共我
    2021-02-01 14:09

    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.

提交回复
热议问题