Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This patch implements formatters for specified number of decimal places and significant figures. It depends on #580540: Implement rounding to significant figures for format_number.module for the significant figures algorithm.
By default it enables formatters for DPs of 0, 1 and 2, and SFs of 1, 2, 3 and 4. However these are overridable by setting Drupal variable or through $conf
in the settings.php file. However there is no UI to change them in this patch.
A screenshot showing the additional formatters is attached.
Comment | File | Size | Author |
---|---|---|---|
formatted_number dp and sf formatters.patch | 3.78 KB | Bevan | |
new formatters-1.png | 19.49 KB | Bevan |
Comments
Comment #1
markus_petrux CreditAttribution: markus_petrux commentedUnfortunately, there's no place in CCK to provide settings for field formatters, and now I'm using the number of decimals defined for the field. There's also a "Remove redundant zeros" formatter. I would not change this, but add only new formatters for the new significant figures format.
Comment #2
Bevan CreditAttribution: Bevan commentedI don't understand your concerns or why you put this to "needs work". Did you review it? I'm confused.
Comment #3
Bevan CreditAttribution: Bevan commentedPerhaps you meant settings for the range of lengths that the module creates formatters for? There is no need for per-formatter settings. That's what these settings are for. They are site-wide Drupal variables that say what formatters to enable. E.g. the default for DP is 0,1,2. So there are three DP formatters, "0 decimal places", "1 decimal places" and "2 decimal places". If the setting was changed to 1,2,6 it would provide formatters for 1 dp, 2 dp and 6 dp.
There is no UI for these settings, but it would be logical to put one on the admin/settings page for the module. IMO the UI should be addressed separately in a different patch. Since this is something that users would rarely need to configure, and already has sensible defaults. Also because the UI, form widgets, UI text and implications of deleting a formatter need considerable thought in order for it to be usable.
Comment #4
markus_petrux CreditAttribution: markus_petrux commentedCommitted a slight different version to CVS (commit).
Differences:
- There's no additional formatter by default. You should add lines to your settings.php file. Described in the README as well as the project page.
- The new theme function also respects prefix and suffix options defined in field settings form.
- Using format_plural() to build the formatter labels.
Thanks!
Comment #5
Bevan CreditAttribution: Bevan commentedGreat! Thanks! :)