public function UnitsEntity::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 UnitsMathematicalExpression::formatQuantity
File
- includes/
UnitsEntity.class.inc, line 61 - Definition of UnitsEntity class.
Class
- UnitsEntity
- Units of measurement entity class.
Code
public function formatQuantity($quantity) {
// We expand this unit into "1 * $this" so we have get a dimensionless
// member that can be formatted. In case this unit decomposes non-linearly,
// we use "quantity" operator instead of multiplication.
$operator = $this
->isLinear() ? 'multiply' : 'non_linear';
return units_mathematical_expression_operator_construct(units_get_operator($operator), new UnitsConstantMathematicalExpression(1), $this)
->formatQuantity($quantity);
}