I would like to change my number format to percentage. I know I can make this in fields pane, but I wanna try to solve it in code bloc through "Calculate Field".
Image 1:
It's in this format that I wanna set, but in python in code bloc.
Many Thanks!!
Are you asking how to taking a number like 0.123 (12.3%) and make it 12.3? If so, just multiply the current value by 100; otherwise, I am not sure what you are asking. The numeric field will never store the percent sign, that is simply a formatting option in a table view. If you want a percent sign with the actual data, you will have to use a string field.
I would like to transform the number "27" into "27%". The way that I know, is to going on field pane and changing "number format" to percentage.
Going in this string field idea, how do I concatenate the symbol "%" into my code bloc?
This scrip in code bloc helps me to get percentage value. If I wanna concatenate an "%" symbol, do I need to write "return round(X,0) + "%"".
I'm asking cus when I made it, it acuses me error.
Many Thanks!
Python has very robust string formatting you can use and it won't require a code block. For the expression, try:
"{:.0%}".format(!condicao!/!total!)
If you want to programmatically set the number format of a field, I don't think you can do that with Python.