# Calculate field result is float with Arc tool, integer with arcpy script

I am trying to calculate a field for some points within a python script using arcpy functions. (This is calculating the percentage visibility from a cumulative viewshed, if that matters.)

``````# Process: Get Count
TotalFlightPoints = int(arcpy.GetCount_management(FlightPath_Pts).getOutput(0))

# Process: Calculate Field (2)
Obsv_Vis = arcpy.CalculateField_management(Obsv_Vis, "PercentVis", "!RASTERVALU! / " + str(TotalFlightPoints), "PYTHON", "")
``````

Even though I cast that field as a FLOAT when adding it, the result is consistently an integer (0 if less than 1, 1 if the point is 100% visible). I can get around this by `"!RASTERVALU! * 100 / " + str(TotalFlightPoints)`, which will at least give me the percentage (without any trailing decimals). That level of accuracy may be sufficient for this application, at least for now.

But, if I use the Field Calculator within ArcMap on a "float" field (with, say, `!RASTERVALU! / 121` as the equation), it gives me the result as a float. So I'm wondering why the field calculator seems to work differently in different situations, and/or what I can tweak to get what I really want.

-
When calculating in the Python script, make sure you force float calculations, e.g. `12/2 = 6`, but `12./2. = 6.0` – Jason Mar 28 '13 at 15:22

@Jason's comment is correct: you need to be dividing by a float, but you define `TotalFlightPoints` as an integer. Try it with
``````TotalFlightPoints = float(arcpy.GetCount_management(FlightPath_Pts).getOutput(0))
Ah yes, I glossed over the first line of code where `TotalFlightPoints` is cast as `int`. This should do it. – Jason Mar 28 '13 at 16:57