I have earthquake data and within the data, there are magnitude, longitude and latitude values. However, these values have around 6/7 decimal places but I would like to only have 2 decimal places for each value, when I export my map. I add the earthquake event through QgsVectorLayer rather than a CSV format when using python and I can access features such as magnitude, longitude and latitude, by using
feat['magnitude']), as can be seen below:
I then add each feature to the layout exporter, ready to export. I have tried various ways to only get 2 decimal places on each feature but non have prevailed as of yet. The ways I have tried are:
format_number(ID, decimal place),
round($ID, decimal places) and
layer.dataProvider().addAttributes([QgsField("fieldname", QVariant.String, "String", 10, 2)]). I may have done part of the code wrong though, hence why it did not work. Each feature is within a string variable but I can not seem to find a way how to convert to double or real. A small snippet of my map is included below where the values of magnitude, longitude and latitude can be seen, so that I would like each value to say 4.39 (Mag), -72.02 (Long) and 6.40 (Lat). Hope this makes sense.