public function AbstractUnitsMathematicalOperator::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
1 method overrides AbstractUnitsMathematicalOperator::formatQuantity()
- UnitsMathematicalOperatorNonLinear::formatQuantity in ./
units.module - Format a certain amount of quantity within this mathematical expression.
File
- ./
units.module, line 1369 - Provide API for managing and converting units of measurement.
Class
- AbstractUnitsMathematicalOperator
- Abstract implementation of "mathematical operator" interface.
Code
public function formatQuantity($quantity) {
$contains_dimensionless1 = $this->operand1
->containsDimensionlessMember();
$contains_dimensionless2 = $this->operand2
->containsDimensionlessMember();
list($quantity1, $quantity2) = $this
->evaluateOperands();
if ($contains_dimensionless1 xor $contains_dimensionless2) {
if ($contains_dimensionless1) {
$this->operand1
->formatQuantity($quantity / $quantity2);
}
else {
$this->operand2
->formatQuantity($quantity / $quantity1);
}
}
else {
$split_quantity = ctools_plugin_get_function($this->operator, 'split quantity callback');
list($quantity1, $quantity2) = $split_quantity($quantity, $quantity1, $quantity2, $this->operator);
$this->operand1
->formatQuantity($quantity1);
$this->operand2
->formatQuantity($quantity2);
}
return $this;
}