/** * Set the rounding mode. * * @param integer $roundingMode A value from the RoundingMode enumeration. * @throws InvalidArgumentException If $roundingMode is not a value from the RoundingMode enumeration. */ public function setRoundingMode($roundingMode) { if (in_array($roundingMode, RoundingMode::asArray())) { $this->roundingMode = $roundingMode; } else { $msg = "The roundingMode argument must be a value from the RoundingMode enumeration, '" . $roundingMode . "' given."; throw new InvalidArgumentException($msg); } }
/** * Unmarshall a QTI roundTo operator element into a RoundTo object. * * @param DOMElement The roundTo element to unmarshall. * @param QtiComponentCollection A collection containing the child Expression objects composing the Operator. * @return QtiComponent A RoundTo object. * @throws UnmarshallingException */ protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($figures = static::getDOMElementAttributeAs($element, 'figures', 'string')) !== null) { if (!Format::isVariableRef($figures)) { $figures = intval($figures); } $object = new RoundTo($children, $figures); if (($roundingMode = static::getDOMElementAttributeAs($element, 'roundingMode')) !== null) { $object->setRoundingMode(RoundingMode::getConstantByName($roundingMode)); } return $object; } else { $msg = "The mandatory attribute 'figures' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
public function createFakeExpression($roundingMode, $figures) { $roundingMode = RoundingMode::getNameByConstant($roundingMode); return $this->createComponentFromXml(' <equalRounded roundingMode="' . $roundingMode . '" figures="' . $figures . '"> <baseValue baseType="float">102.155</baseValue> <baseValue baseType="float">1065.155</baseValue> </equalRounded> '); }