Rounding decimals up using the field calculator

5255
11
Jump to solution
02-23-2011 12:48 AM
EdelSødal_Pedersen
New Contributor
Hi,

I'm new to python and couldn't find an answer elsewhere to this problem. And I guess it's not a big deal actually, but I just don't get it...

Code Block:
def tvol(a, b, area):
if (a >=2):
  return a*b/100

Expression:
tvol(!a!, !b!, !AREA!)

How do I get rounded values in the end, like VB would do. F. ex. 35.5 --> 36 and not 35, 35.4 --> 35.
Someone having an idea how to put this into the above script?

Thanks!
Tags (2)
0 Kudos
11 Replies
EdelSødal_Pedersen
New Contributor
Hi,

replace the !A! and !B! with the fieldnames you want to use for the calculation.
If you want results without decimals use: round(!A!* !B! /10) and with decimal places: round(!A!* !B! /10.0)
10.0 could be any number you want to use, you just have to define the number of decimals, even if the field type is double and allows more decimals the script will not return more than what you have defined within the script.
Hope that helps!
0 Kudos
ChrisGraves
Occasional Contributor
Hi Iris,

Thanks for your reply this has given me what I need and I've learn't something too!

Have a good day.

Thankyou,

Chris
0 Kudos