Converting Feet and inches e.g. 5' 10" to whole number inches...

11-17-2019 03:57 PM
New Contributor

I have a field "height" and its in x" y' . I need to convert this to inches and then multiple by 2.54 to update "height_cm" field.

3 Replies
MVP Legendary Contributor

Nothing like a brain warmup before going to sleep;)

If you have any blanks or nulls, I don't check for them so only run this in the field calculator for valid heights

The result is a number, if you want a string replace line 7 with

return str((a + b) *2.54);‍

# ---- python code block section
def metric_is_better(val):
    r"""convert from 6' 2" to metric"""
    ft, inch = val.split(" ")
    a = int(ft[0]) * 12
    b = int(inch[0])
    return (a + b) *2.54
# expression


Yes... this is how you have to encode when you use
' and " in strings

val = r"""6' 2\""""

'6\' 2\\"'

187.96  # the result‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
New Contributor

How would this work for a list of attributes (entire table)? Goal is to not alter the height column but to read the imperial units x'x" in column height and populate another column height_cm

0 Kudos
MVP Legendary Contributor

Using Calculate Field

Calculate Field—Data Management toolbox | ArcGIS Desktop 

with the Python parser and a code block