Safest way to convert float to integer in python?

后端 未结 10 2572
不思量自难忘°
不思量自难忘° 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条回答
  •  暖寄归人
    2020-11-27 14:09

    Use int(your non integer number) will nail it.

    print int(2.3) # "2"
    print int(math.sqrt(5)) # "2"
    

提交回复
热议问题