Safest way to convert float to integer in python?

后端 未结 10 2555
不思量自难忘°
不思量自难忘° 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 13:58

    Another code sample to convert a real/float to an integer using variables. "vel" is a real/float number and converted to the next highest INTEGER, "newvel".

    import arcpy.math, os, sys, arcpy.da
    .
    .
    with arcpy.da.SearchCursor(densifybkp,[floseg,vel,Length]) as cursor:
     for row in cursor:
        curvel = float(row[1])
        newvel = int(math.ceil(curvel))
    

提交回复
热议问题