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.

1 Answer 1


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"
  • Aha! Yes they are integer fields. That worked. Thanks!
    – Andrew
    Sep 22, 2014 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.