1

I am trying to calculate a percentage in a field in a table. customers and total_customers are short integer fields.

arcpy.AddField_management(tableSepSel2, "percent", "DOUBLE")
arcpy.CalculateField_management(tableSepSel2, "percent", "!customers! / !total_customers!*100", "PYTHON_9.3")

I don't get any errors but all the values in the percent field are zero when most of them should not be zero.

If I go into ArcMap and use the field calculator with the Python parser, the same thing happens. However, when I choose the VBScript parser in ArcMap and redo the code using brackets it works fine.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 22, 2014 at 15:35

1 Answer 1

5

I'm guessing customers and total_customers are integer fields, and the equation is using integer math, yielding the rounded-down result (0 * 100) in every case except where customers == total_customers (1 * 100).

Use this equation to get decimal calculations:

"float(!customers!) / float(!total_customers!) * 100"
answered Sep 22, 2014 at 16:08
1
  • Aha! Yes they are integer fields. That worked. Thanks! Commented Sep 22, 2014 at 16:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.