3

I'm trying to figure out how to display one attribute column in percentages. I've created a new field inside the attribute table and proceeded with:

concat("column with numbers to be changed in percentage",'%')

But the output displays NULL. Any insight on what I may be doing wrong?

  • Are you just looking to put a % at the end of a number, or are you trying to convert a decimal to a whole number as a percent? – DPSSpatial Jan 24 at 17:52
  • @DPSSpatial I'm trying to convert a decimal to a whole number as a percent! – Tim56 Jan 24 at 18:37
  • Gotcha!! Let me add an answer... – DPSSpatial Jan 24 at 18:42
3

Given decimal values in a double precision column (or other), you can use an expression to:

  • multiply the value by 100
  • round the value to 0 decimal places
  • concatenate the % sign at the end of the value

In a label expression, this is what I would do:

(my percent column is called "rating")

round(("rating"*100), 0) || '%'

I use the label expression rather than creating a new column of otherwise redundant data.

enter image description here

Here I've added both the original column and the percent-formatted column on two lines of the label:

"rating" ||  '\n' ||
round(("rating"*100), 0) || '%'
|improve this answer|||||
  • that's exactly what I was looking for, great input cheers! – Tim56 Jan 27 at 8:14
  • @Guillaume good stuff! Thanks!! – DPSSpatial Jan 27 at 13:51
4

you need to use to_string expression, when use numbers in concat, like this:

concat(to_string("column with numbers to be changed in percentage"), ' %')

I hope, this will be helpful for you.

enter image description here

Results:

enter image description here

|improve this answer|||||
  • many thanks for your input, however, the result of the formula is still giving me "NULL"... – Tim56 Jan 24 at 15:04
  • 1
    @Guillaume, I prove the code, and words in my Qgis, It is possible that you are using a field that can support string, or is not possible to edit this field, try to create a new column that supports string, I think this will works. I edit the answer to you can reply the code. – Jhon Galindo Jan 24 at 15:14
2

To concat two strings you can use '||'.

So the expression would look like this:

 to_string("column with numbers to be changed in percentage" ) || '%'
|improve this answer|||||

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.