Is there a way to format the way attribute values are displayed in the attribute table?
For example, I would rather display the following columns to show comma-separated thousands and without the zeroes after the decimal point.
unformatted view attribute table
So, instead of "2300000.00000", it would display as "2,300,000" instead.
2 Answers 2
You cannot format the numbers directly, you need to create a field of type String
first then use the following formula using Field Calculator in QGIS:
format_number(Field_name,0)
The format number is located under String category that's why creating a field of type String
is necessary.
For example if you have a field of type Real
with a name X , then add a field of type String
and the formula will be format_number("X",0)
. The 0 is to remove any decimal places and add comma-separated thousands.
-
I'm knocking myself on the head for not remembering how powerful the Field Calculator is! Thank you @ahmadhanbn1kn0k– n1kn0k2016年08月03日 00:22:43 +00:00Commented Aug 3, 2016 at 0:22
-
It works great but it would be nice to have a 'format' option in Layer properties -> Fields.Victor– Victor2016年08月04日 14:45:36 +00:00Commented Aug 4, 2016 at 14:45
-
@Victor I agree with you, I hope it can be added in the future.ahmadhanb– ahmadhanb2016年08月04日 14:56:32 +00:00Commented Aug 4, 2016 at 14:56
Great answer from @ahmadhanb which as mentioned, there doesn't seem to be away (yet) to change the formatting display of the attribute table! Another method is to use the Float to Text
tool from the MMQGIS plugin, this tool converts your float fields into string automatically and outputs the result as a new shapefile. You can download/enable the plugin from the menubar.
Plugins > Manage and Install Plugins...
Example attribute table:
From the menubar:
MMQGIS > Modify > Float to Text
Set the relevant options (the output must be saved somewhere other than the temp folder)
Result: