/** * @param self $number * @return string */ public static function toString(self $number) { $string = $number->isNegative() ? '-' : ''; $string .= $number->getNumerator(); if ($number->isFraction()) { $string .= sprintf('/%d', $number->getDenominator()); } return $string; }
/** * @return Numericity */ protected function parse() { $numericType = $this->parseNumericType(); $numericValue = $this->getAttribute(self::ATTR_NUMERIC_VALUE); if ($numericValue === self::NOT_A_NUMBER) { return new NonNumeric($numericType); } $numericValue = RationalNumber::fromString($numericValue); return new Numeric($numericType, $numericValue); }