Numeric Scale Formatter

Component ID

2841187

Component name

Numeric Scale Formatter

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

This module provides two "Scaled" format options for numeric fields:

  • Short Scale
  • Full Scale

Before going into the difference between the two formats let's discuss about something they have in common: Scales.

Numeric Scales

There are a few predefined scales ready to be used (for example Metric and Imperial systems). However, you are free to customize or redefine them.
Most importantly is to use a scale with the correct unit (factor=1). For example, if the field represents a distance in kilometers, do not use the default Metric scale. Use a customized version where km has a factor of 1 and meter (m) has a factor of 0.001 (or 1e-3).

Short Scale

This format is very useful when the exact value is not important and you want to display an easy to understand approximation.
Here are some examples:

1000 => 1k
12345 => 12.3k
23453453 => 23.4M
4239472929375 =>4.2T 

Full Scale

This format is useful if a longer representation is desired, not only the most significant factor.

1000 => 1k
12345 => 12k 345
23453453 => 23M 453k 453
4239472929375 =>4T 239G 472M  - cap verbosity with "Maximum factors shown" option 
120.75 => 120km 750m   - considering a distance in km

Similar projects

Some recognition should go to Short Scale Formatter as the original inspiration for this module. Unfortunately, that module had not been converted to Drupal 8; it only handles integer values and it has a very limited scale (thousands, millions, billions and trillions).