Safest way to convert float to integer in python?

后端 未结 10 2554
不思量自难忘°
不思量自难忘° 2020-11-27 13:44

Python\'s math module contain handy functions like floor & ceil. These functions take a floating point number and return the nearest integer be

10条回答
  •  -上瘾入骨i
    2020-11-27 13:50

    Combining two of the previous results, we have:

    int(round(some_float))
    

    This converts a float to an integer fairly dependably.

提交回复
热议问题