Changing CSV layer attribute value from text to number in QGIS?

I once had the same question. The answer is that you put a file in the same folder with the ending csvt. For example your file name is xyzdata.csv you add the file xyzdata.csvt

This one you can edit with editor for example. And in it you set the data type like this. "Integer","String","Integer","Integer","String","Real"

Integer is now the variable for the first column, string for the second and so on... Make sure the files are named identically.

Edit: See here too if needed: http://underdark.wordpress.com/2011/03/07/how-to-specify-data-types-of-csv-columns-for-use-in-qgis/


Rather than messing with the input file, trying to get everything picture perfect, just use the field calculator to convert the text to a number / real. See the examples below:

Field Calculator

Field Calculator to Number

Field Calculator to Real

Attribute Table After Function


Instead of loading the .csv using Add vector layer, use the Delimited Text layer tool. It will try to detect the most fitting data type for each column.

For more details see the QGIS user guide.

enter image description here