2

I am using a graduated legend, using the default format "%1 - %2". The numbers are formatted using decimal points, like "1.1 - 1.2".

How could I change this to using decimal commas, like "1,1 - 1,2"?

I tried the suggestion below, changing the locale to Dutch (interface language still American English. That does change the format of the values, but not the legend (see screenshot), which is what I need.

enter image description here

4

2 Answers 2

4

The following is a bit of a kludge, but it can be done in map layouts, and avoids mucking around with locale settings.

In the layer properties, keep the legend format as %1 - %2.

In the legend definition on your layout, edit the expression for the layer in the legend (the curly E button in the icons at the bottom when you have the layer entry selected; not the individual graduated children but the whole layer; and also not the 2nd E at the far bottom right which relates to filtering). Replace @symbol_label with replace( @symbol_label,'.',',').

This works by post-processing the string generated by the %1 - %2 and doing a string replace of decimal point by comma. You could get much fancier if you needed to by changing the legend format to some format easier to re-parse into its constituents and then extracting those constituents and formating it in a more sophisticated way using full expression syntax in the layout label expression, if you needed to. I have used this, for instance, to show graduated levels both in (native) metres as well as converted to feet.

4
  • Thanks, that works, but is quite weird indeed. I would have expected that a locale could be specified for something like a legend. The decimal dots are indeed replacable, other locales could maybe not be implemented this way. BTW, changing the windows locale was never an option as I also have to work with data in language dependent formats like csv. Jul 9, 2020 at 13:46
  • It might maybe be an idea to be able to use formulas in the legend format specification "%1 - %2", so one could for instance, do "format_number(%1,1,'nl') - format_number(%2,1,'nl')"? Jul 9, 2020 at 14:07
  • @HendriAdriaens, yes it would be nice. I haven't checked it, but I strongly suspect QGIS' implementation of legend format is coded as an invocation of QString::arg or something similar. This only allows simple replacement of numbered arguments %1, '%2', etc. What you are proposing would replace that with full access to QGIS' Expression logic, and would not be trivial -- though would definitely open up interesting possibilities!
    – Houska
    Jul 9, 2020 at 16:09
  • Thanks. I wonder how one can work with QGis when producing maps with legend in a different locale. I can't imagine I am the first to encounter this. Changing the locale of your OS temporarily does not seem to be a solution here as that might make your data (like locale-depending csv) impossible to read. Jul 13, 2020 at 7:04
3

The behaviour of QGIS is defined inside project definition: QGIS can either use completely system setting of your computer or override it (entirely or partly - as you like).

You can manage the behaviour of QGIS inside the opened QGIS project by clicking Settings/Options. In the search mask fill in locale (as shown in the screenshot):

enter image description here

I'm using an english interface, but as a locale german notations for data, money and floats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.