Creating label formatted like " 1,000' " from numeric field?
Using two string functions in the QGIS calculator on version 2.6 Mac OS X I was able to accomplish this. Here are the steps:
Using the field calculator create a new field that is a string type with a relevant width.
Run the following expression to set the value of the field:
concat( format_number( "Field_name" , 0) , '\'')
This created a column with a string formatted as I wanted so for example the number 2000
would be formatted to 2,000'
with the trailing '
which stands for feet.
QGIS has created a function called format_number
to address this. You simply do format_number(12345,0)
to get 12,345
.
You can do digit grouping easily in Python. Here's a function that I've used, which I think I found on StackOverflow:
def digitgroup(n, sep = ','):
if n == "": n = 0
s = str(n)[::-1]
groups = []
i = 0
while i < len(s):
groups.append(s[i:i+3])
i += 3
return sep.join(groups)[::-1]