0

What is the syntax to build to calculate field, for example,

Acres to Percent?

841173.00 to 82 %

What I want the field column in Percent to be display numbers with percent with the alignment to the right of 2 characters? How is that possible?

I can run from the Calculate field toolbox and then use the Field Calculator and insert the expression with the python syntax.

Example of from Acres to Percent

I had to manually right click on the Percent field column's properties to get to the Percentage under the Number Format and change it from there. I feel this is a time-consumed for me because I will be doing this for about 80 of them. I want to get the expression and let it run from the Calculate Field.

  • I'm not sure I understand the question. What is the percentage based on? If it is based on an existing value, then I'm not sure why you would need python for this. As you indicate, you can just use the field calculator and format it as a percentage. What information am I missing? – jbchurchill Jul 21 '14 at 17:11
  • This would be better as a comment to the original question, rather than an answer. – Erica Jul 21 '14 at 17:12
  • Good point. I don't see how I can edit it as such. – jbchurchill Jul 21 '14 at 17:17
  • 2
    Why would someone downvote on me ? I was trying to ask someone to help me and others comment on my question. Thank you for downvote one me That just shows disrespect me. If you don't understand someone Ask first before you downvote. – PROBERT Jul 21 '14 at 18:46
  • @PROBERT, it's likely because this question is primarily python related, not ArcMap specific (look no further than the title). It's not disrespectful to downvote questions. As it stands, this question doesn't appear to have much in relation to GIS. – Paul Jul 21 '14 at 19:37
1
  1. Add a new field (text)
  2. In field calculator, round the original Percent value to no decimals, and append a percent sign:

    • format(round(!Percent!)) + "%"

    • or the shorter, more elegant "{}%".format(round(!Percent!))

(Thanks to Paul for the improved syntax!)

  • Would that work in Model Builder ? – PROBERT Jul 21 '14 at 17:18
  • Why wrap int(!Percent!) in format() instead of str()? Or, the simpler "{}%".format(int(!Percent!)). – Paul Jul 21 '14 at 17:23
  • Also, you might want to use round() instead of int(). – Paul Jul 21 '14 at 17:28
  • @Paul -- my Python syntax is still a work in progress, I appreciate the suggestions :) – Erica Jul 21 '14 at 17:34
  • @PROBERT -- Yes, following more or less the same workflow as in this other answer – Erica Jul 21 '14 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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