It would be nice to have the ability to add text fields for prefix and suffix, as is available in CCK integer and decimal fields. I originally handled this in the PHP code by appending the suffix text. The problem however as I much later discovered is that Views did not sort the resulting value properly because it was stored as text, not an integer type in the DB. If you want Views to sort this filed properly it cannot be stored as text, hence the requirement to have fields for such text, just as with the CCK number fields.
Also, if you store the field as an integer, allow for standard display formatting as with the integer field, so 1234567 looks like, for example, 1,234,567.
Comments
Comment #1
Moonshine commentedYou actually have complete control over what is displayed via the "Display Format" section of the field configuration. For example if you wanted to do some US money you could do a float field with (admittedly dumb) computed code of:
and then a display format of:
And you'd have proper number values stored like 12345.67 in the database, and "$12,345.67" output for display
Comment #2
druplicate commentedThanks, I'd overlooked that capability. I had used number_format in a custom tpl.php file to get the thousands separator. So I changed the tpl.php to display the variable alone, and added the number_format to the display style as you suggested (
$display = number_format($node_field_item['value']);) but it didn't display properly. The field is an integer type and as an example the stored computed value is 79000.The help text for computed field says, "Note: this code has no effect if you use the "Computed Value" formatter option.", but I found the reverse was true - I had to use the "Computed Value" formatter option to get it to work - any other format option failed. I would have expected that "Markup" would be the correct formatter but it spit out "0" instead of the correct value, 79,000. Using the "Raw Text" formatter spit out "79".
I was also displaying the computed field in a view and the thousands separator comma didn't display because there was no way to apply number_format to the Views field without making another tpl.php. Now however, it works by using the "Markup" Views formatter.
Strange results. I changed the status to an active bug report because it appears the behavior of the "Markup" and "Computed Value" formatters for the node output is wrong.
UPDATE: I have no idea what was going on, probably because of caching, but when I loaded the site to a new server it became necessary to change the node display formatter option to "Plain Text". Using "Markup" inserted an extra p tag, and true to the help text, using "Calculated Value" removed the formatting. Now everything behaves as expected - I get the formatting in the node display and in a View.
Comment #3
dqdDue to the Drupal core life cycle policy and security support advisery, Drupal 6 is no longer supported. So issues for Drupal 6 cannot be longer maintained. The project maintainer has asked for closing all D6 issues to clean up the issue queue. Feel free to reopen the issue if required or set it to "needs to be ported" and latest D8 dev version, if the issue discusses a still missing feature which can be implemented in the D8 version.