0

I have the following VB code to produce a percentage in a field calculator.

" [FIELD_1] / [Total]*100 "

It works in VB. I've tried the following without luck.

!FIELD_1! / !Total! * 100

Can anyone translate this VB code to python?

5
  • Can we see a screenshot of your field calculator, with the python code in it?
    – Thomas
    Commented Oct 8, 2015 at 20:57
  • Did you change the expression type to Python?
    – Paul
    Commented Oct 8, 2015 at 20:57
  • Yes. The expression was changed to python.
    – MapGeo
    Commented Oct 8, 2015 at 21:05
  • Hi. Here is a screen shot: imgur.com/QtkqxvS
    – MapGeo
    Commented Oct 8, 2015 at 21:51
  • Please be more specific than "I've tried the following without luck" or other things like "it didn't work" when asking questions. Unless the issue is blindingly obvious, that does not provide enough information for us answer you. In future, describe the results you actually got, whether it's an error message (include it) or incorrect values (provide examples). Please also provide more details, such as the data types of the fields in your expression.
    – user2856
    Commented Oct 9, 2015 at 8:26

1 Answer 1

3

Note, in python, division between integers will produce an integer. You will need to cast one of the variables as a float to produce the results you want.

float(!FIELD_1!) / !Total! * 100

Also, ensure the field you are running this in supports decimals - float or double.

Your Answer

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

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