This project is not covered by Drupal’s security advisory policy.


THIS PROJECT HAS NO (FINAL / WORKING) CODE YET! PLEASE PARTICIPATE!

(Read the project description and issues)


Provides advanced number formatting and rounding options for
  • Float
  • Integer

fields.

Integer would also work but doesn't make sense from my point of view, because the core formatters already provide everything needed for integers, I think. No rounding is needed.

The long term aim of this module is to provide a central number formatting system with i18n support like it exists for date / time in core. Number formatting should be handled similar and I'd hope the results will one day become part of Drupal core!

Your help is required!

This is no small or unimportant project, but may be a nice step for Drupal. Experienced developers and organizations wanted to become project maintainers (or sponsors)!
I'd be happy to achieve the project goals together with other developers! :)

Project goals / milestones:

Step 0: Documentation & Tests

Write down what we want to achieve and write tests for that.

Step 1: Field formatter (coding)

Add advanced number formatter for decimal and float with settings for:

  • Decimal point symbol (**Inherited**)
  • Thousands separator symbol (**Inherited**)
  • Select: Rounding (see https://en.wikipedia.org/wiki/Rounding) **New**:
    • No rounding (output as entered - allows different decimal lengths **hides decimals setting**)
    • Commercial / comon rounding (round half away from zero DIN 1333 (**Decimals as set**)
    • Round half to even (nearest integer, IEEE-754 **Decimals as set**)
    • Round up (ceiling **Decimals as set**)
    • Round down (floor **Decimals as set**)
    • Truncate (substr **Decimals as set**)
  • Decimals (length) (**Inherited**)
  • Checkbox: Zero padding (fill decimals with zeros if less decimals entered than decimal length set **New**)

Step 2: Central configuration & profiles (coding)

Define central profiles / defaults for the settings above (like for date formats) and i18n. They can be selected in the formatter or "custom" can be set (which replaces the above settings)

Step 3: Contrib support / enhancements (coding)

Contrib module support:

Step 4: Core integration (possibly)

Core integration if the core maintainers agree it's useful enough:
#52153: Add Number::format with settings to configure decimal point and thousands separators

Step 5: Backport to Drupal 7

If someone wants to, this may be backported to Drupal 7. A basic functionality like this is missing since Drupal 6. :)

Alternative modules

Drupal 8:

Drupal 7

Development proudly sponsored by German Drupal Friends & Companies:

webks: websolutions kept simple (https://www.webks.de)
and
DROWL: Drupalbasierte Lösungen aus Ostwestfalen-Lippe (OWL), Germany (https://www.drowl.de)

Supporting organizations: 
proudly developed this module for the community!

Project information

Releases