# Converting real number fields to a simple integer field

I have a shapefile with attribute table that has number fields that have five zeros after the decimal point, having been imported that way. I don't need decimals and want the figures as simple intigers. How can I convert them in QGIS?

• Welcome to GIS:SE @David Heslop! If you create a new integer field, you can use the name of the field with numbers as the expression (e.g. "fieldName"). Or you can use the expression to_int( "fieldName" ) to convert your real number to integer. Dec 9, 2016 at 12:12
• not true: you cannot use to_int("yourfieldname") with a real number, only with a string... please check before answering... :-)
– ddb
Apr 28, 2019 at 12:09
• Well, it's true what's documented is the use of to_int to convert from string to integer, but it's also true that it works to directly convert from double numbers to integer, at least in QGIS 3.16. You can try in Field Calculator, to_int(3.4) for example gives 3 and to_int(3.6) 4. That is, it rounds the real number. Nov 28, 2020 at 14:12

Open attribute table and go to field calculator, then create new column (integer) with expression "YourColumnName".

Obviously you have to change YourColumnName with name of your column where you have old values.

• That is absolutely brilliant Works fine. - thank you. I even know how to spell "integer" now!!! Dec 9, 2016 at 15:32

To convert real to integer in an expression, you can round the real number, convert to string and then convert to integer:

to_int( to_string( round("yourfieldname") ) )

It is a bit convoluted, but it works for me.

• You don't need to convert it to string or round it. to_int(doublenumber) rounds it to an integer in field calculator. Nov 28, 2020 at 14:13