4

I have a string field populated with shape lengths in my attribute table but they have 12 decimal points. How do you remove decimal points from a string field populated with numbers using the field calculator?

  • 2
    With Python, it's quite simple: int(float(!FieldName!)) – Paul Apr 7 '16 at 16:30
3

You can do this with a string with the following VBA in the field calculator:

Left([FIELD_NAME], InStr(1,[FIELD_NAME], ".") - 1)

That will remove the decimal and everything after. If you want some number of digits after the decimal, replace the -1 with + like so:

  Left([FIELD_NAME], InStr(1,[FIELD_NAME], ".") + 2) 

will give you 2 decimal places. However, this is going to throw errors if some rows have fewer decimal places than you're shortening to. Goldring's answer may be more stable and universal, but if you know your data, you can do it directly in a string field.

1

If you're trying to get rid of the decimal and everything to the right of it, you should be able to do something like this:

Left([field],InStr([field],".")-1)
1

Note that my answer here is for when you want the result of this to be used in other potential field calculations where it draws from other fields.

Create a new field that is the same data type as your original shape lengths field (probably a double). When creating the new field, make sure it has the following parameters:

  1. A 'Precision' that is something high, like 20. Precision is the maximum number of digits allowed. So essentially you want to make sure the max is above the total number of digits you have in the shape_length field.
  2. To ensure you do not want any decimal points, put in a 'Scale' of '0'.

From here you can calculate into this field the original shape length field. Now the shape length should not have any decimal.

Next step, field calculate into the string field from the field you just calculated into that has no decimal points.

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.