When I save a csv as shapefile the fields with decimals are saved adding decimals, then the new table in some case has new values.

Old Table (CSV)

1.94        39.6
-11.19      28.22
-36.88      2.59
-33.64      6.08

New Table (DBF/SHP)

  • how did you save the file? Tried the mmqgis plugin? – Curlew Jul 10 '14 at 12:10
  • Hi, Curlew. I use "Add delimited text layer" then I save the layer as .shp using "Save as..." – user34380 Jul 10 '14 at 12:30
  • Curlew, I have used mmggis and it works fine. Thank you. – user34380 Jul 10 '14 at 12:36
  • I realize about that issue because when I tried to publish this layer as WFS using geoserver nothing is showed (no objects neither values in the table) just the field names in the table. – user34380 Jul 10 '14 at 12:39
  • I noticed that all fields are created as String when I use mmqgis. – user34380 Jul 10 '14 at 13:58

I see that you were able to use a plugin to get the values you wanted, but here's why the values were changing in the first place.

This isn't specific to QGIS or any other software, it's an issue with how the data is being stored. Floating point values are stored with a specific precision (number of digits). Some software will automatically round the stored values when displaying them but it's all stored the same.

For example, I can reproduce your values in Python:

The value prints out normally within the precision of the float type:

In [35]: '{0:2.14f}'.format(28.22)
Out[35]: '28.22000000000000'

but not if you try to print more precision than is stored:

In [36]: '{0:2.15f}'.format(28.22)
Out[36]: '28.219999999999999'

In some cases you may be able to store your values as strings (which may be what that plugin is doing), but that also has issues and won't work in all cases.

  • Thank you Evil Genius, I have noticed what you say in ypur last paragraph in my own data. So, this is not the solution I am looking for. – user34380 Jul 10 '14 at 14:01

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.