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

Amount provides a numerical field coupled with an associated "units" property so it is known what the number refers to.

Although the internal characteristics can be adjusted, Amount should serve most numerical needs with its defaults. Storage and computation are efficient and accurate and cover a huge range.

How big a range and how accurate? Here are some examples of the range and precision of the Amount field:

  1. Amount can store time at a resolution of micro-seconds for a span of 557,000 years
  2. Amount can keep track of distances as small as a VLSI transistor over a span of a couple of our Solar systems.

The numerical field is maintained as a 64-bit integer referring to fractional portion of the units property. The default is a fractional amount of millionths (10^-6). Therefore, when you store the number one, it gets stored as 1,000,000 by default.

Units are integral by design and include a type, code, symbol, and multiplier. Units supplied by default include quantities, some currencies, temperature, distance, and more.

More units can be defined using the hook_amount_mapping_alter().

The advantages of dealing with integers:

  • Integers are a computer's native number format
  • Simple math operations like addition, subtraction, and multiplication can be done without using floating point libraries
  • Relative database updates can be done using an update operation to adjust quantities relative to the current amount, where semaphores for preventing data collisions are handled natively by the database manager.

The only caveat is that Amount really wants your Drupal site to be running 64-bit versions of everything: operating system, PHP, etc. This shouldn't be a problem for most people as most servers are already running in 64-bit mode or can be configured that way.

Similar modules:

  • Number -- part of Drupal core defines three distinct numerical types each with its own properties defined by internal storage
  • Commerce Price -- part of Drupal commerce: defines a price field stored as a string with hundredths or millionths units as the precision. Currency is attached to each price field.
  • BigInt -- defines a 64-bit integer field with no associated units.
  • Fraction -- defines a numerical field as a 64-bit numerator with an integer denominator. Division is always necessary to evaluate the actual value and no units are integrated.

This project is mirrored on Bitbucket and Github.

As of version 2, Amount is a Y module.

Project information

Releases