2

Using [%round(map_get(item_variables('MyMap'),'map_scale'))%] in a text field in the print composer we can retrieve scale of the targeted map item. The output of the expression is e.g. 10000 - but I would like to add a thousand separator, so the output looks like 10,000.

I am aware that I could check for length of returned string and add the separators by concatenation, but that is tedious to create, error-prone and needs an additional check for lengths above 6 digits, too.

So, using QGIS 3.10 is there an option to add the thousand separator to the returned value of the expression mentioned at the beginning?


Side note: Using the numeric scale bar is possible, but not desired, since I want to incorporate the variable into a small text item.

2
  • 2
    format_number ? – Snaileater Nov 19 '20 at 10:26
  • @snaileater quite straightforward, thanks. – Erik Nov 19 '20 at 10:54
2

As suggested by @snaileater, you can use format_number like so:

 format_number( round(map_get(item_variables('myMap'),'map_scale')),0)

This will make your number a string and add commas as thousand separator, you can specify a language to determine what formatting will be used.

enter image description here

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.