You are here

public function UnitsMathematicalOperatorNonLinear::formatQuantity in Units of Measurement 7.2

Format a certain amount of quantity within this mathematical expression.

Parameters

float $quantity: Quantity to be formatted

Return value

UnitsMathematicalExpression Formatted quantity into this mathematical expression. Sometimes the mathematical expression itself must mutate in order to format the quantity. So the returned mathematical expression may not necessarily be the mathematical expression on which this method was invoked. For example, the expression "unit" would mutate into "1 * unit" in order to have a dimensionless member and therefore be able to format the $quantity

Overrides AbstractUnitsMathematicalOperator::formatQuantity

File

./units.module, line 1649
Provide API for managing and converting units of measurement.

Class

UnitsMathematicalOperatorNonLinear
Implementation of "mathematical operator" interface for non-linear operation.

Code

public function formatQuantity($quantity) {
  $unit = $this
    ->nonLinearMember();
  $decomposition = $unit
    ->inverseDecompose();

  // Swap the quantity placeholder with the real value.
  $decomposition = units_mathematical_expression_create_from_postfix(str_replace(UNITS_QUANTITY, $quantity, $decomposition
    ->toPostfix()))
    ->getExpression();
  $this
    ->linearMember()
    ->formatQuantity($decomposition
    ->evaluate());
  return $this;
}