I have QGIS 2.18.3 installed. I'm trying to create a printable .pdf map with QGIS Print Composer. It needs to have X & Y coordinates listed in an attribute table, with 3 decimals accuracy.
Print Composer has a separate button for "Add attribute table". I added the table using this feature, but found out, that it looses the trailing zeroes after my coordinate decimals.
For example, the original data has X-coordinate listed as "6818424.020", but Print Composers "Add attribute table" feature lists that same coordinate like this "6818424.02".
It is required for my work to display coordinates with 3-decimals accuracy. I could not find any option to add trailing zeroes at any precision, not to mention with 3 decimals.
Is there any way to change how (with what accuracy) trailing zeroes are displayed in Print Composers attribute table? I know this is possible in Arcmap (which I have no access to at the moment), but cant find this in QGIS.
1 Answer 1
In the Attributes option for your table (red circle), click the Expression icon (blue circle) and use the format_number function:
format_number( fieldName, 3 )
This should truncate your values to 3 decimal places:
If you do not want the thousand separator (which occurs when using format_number
), you can include the replace
function:
replace(format_number(reals, 3 ), ',', '')
-
1Thank you! This solved my problem completely! A colleague of mine just asked about thousands separator, whether or not it could be removed. Now I know that too! Many thanks!Sisuaski– Sisuaski2018年01月26日 12:24:02 +00:00Commented Jan 26, 2018 at 12:24
-
@Gifupack - Most welcome! Glad it helped :)Joseph– Joseph2018年01月26日 12:26:04 +00:00Commented Jan 26, 2018 at 12:26
-
Hi! I have a little follow-up question to this. I noticed, there was no comma as thousands separator, but it was done with space "X= 6 835 189,999" and "Y= 24 490 740,986". Don't know if that's related to computer settings or not. But what would be correct way to type the replace function, to prevent spaces from appearing? ( "X= 6 835 189,999" ---> "X= 6835189,999") It must be something like: replace(format_number(reals, 3 )xxxxxxxxxx)?Sisuaski– Sisuaski2018年02月01日 10:44:22 +00:00Commented Feb 1, 2018 at 10:44
-
@Sisuaski Hello! I'm guessing it's a computer or locale (language) setting but you could try
replace(format_number(reals, 3 ), ' ', '')
. Note the space in' '
which is what you want to replace with.Joseph– Joseph2018年02月01日 10:52:37 +00:00Commented Feb 1, 2018 at 10:52 -
1Thank you for your help! I tried your previous tip, it worked on some extent and did not on some. I kind of solved this the "not-so-smart" way, that works for now in my local work. However it does not work when handling data from Oracle DB, which I don't have access to create new tables. I created two new TEXT fields to my shapefile and calculated coordinates with 3 decimals to those text fields. These numbers / trailing zeros that are stored as "text" do not get removed automatically. This works as a test, but for the future, lets hope they add "amount of trailing zeros" -function etc. :)Sisuaski– Sisuaski2018年02月07日 06:32:41 +00:00Commented Feb 7, 2018 at 6:32
Explore related questions
See similar questions with these tags.