/** * @param int $number * * @return string */ protected function toWords($number) { if ($number === 0) { return Dictionary::$zero; } $triplets = $this->numberToTripletsConverter->convertToTriplets(abs($number)); $transformedNumber = $this->buildWordsFromTriplets($triplets); return $number < 0 ? Dictionary::MINUS . ' ' . $transformedNumber : $transformedNumber; }
/** * @param int $num * * @return string */ protected function toWords($num) { $return = ''; if ($num === 0) { return BelgianDictionary::$zero; } if ($num < 0) { $return = BelgianDictionary::$minus . BelgianDictionary::$wordSeparator; $num *= -1; } $numberGroups = $this->numberToTripletsConverter->convertToTriplets($num); $sizeOfNumberGroups = count($numberGroups); foreach ($numberGroups as $i => $number) { // what is the corresponding exponent for the current group $pow = $sizeOfNumberGroups - $i; // skip processment for empty groups if ($number != '000') { if ($number != 1 || $pow != 2) { $return .= $this->showDigitsGroup($number, $i + 1 == $sizeOfNumberGroups || $pow > 2) . BelgianDictionary::$wordSeparator; } $return .= BelgianDictionary::$exponent[($pow - 1) * 3]; if ($pow > 2 && $number > 1) { $return .= BelgianDictionary::$pluralSuffix; } $return .= BelgianDictionary::$wordSeparator; } } return rtrim($return, BelgianDictionary::$wordSeparator); }
/** * @param int $number * * @return array */ private function getWordsBySplittingIntoTriplets($number) { $words = []; $triplets = $this->numberToTripletsConverter->convertToTriplets($number); foreach ($triplets as $i => $triplet) { if ($triplet > 0) { $words[] = $this->tripletTransformer->transformToWords($triplet); if (null !== $this->exponentInflector) { $words[] = $this->exponentInflector->inflectExponent($triplet, count($triplets) - $i - 1); } } } return $words; }
/** * @param int $num * @param array $noun * * @return string */ protected function toWords($num = 0, $noun = []) { if (empty($noun)) { $noun = [null, null, Gender::GENDER_ABSTRACT]; } $ret = ''; if ($num === 0) { return Dictionary::$numbers[0]; } if ($num < 0) { $ret = Dictionary::$minus . Dictionary::$wordSeparator; $num *= -1; } // One is a special case if ($num === 1) { $ret = $this->getNumberInflectionForGender(Dictionary::$numbers[1], $noun); if ($noun[2] !== Gender::GENDER_ABSTRACT) { $ret .= Dictionary::$wordSeparator . $this->getNounDeclensionForNumber('o', $noun); } return $ret; } $numberGroups = $this->numberToTripletsConverter->convertToTriplets($num); $sizeOfNumberGroups = count($numberGroups); $showedNoun = false; foreach ($numberGroups as $i => $number) { $power = $sizeOfNumberGroups - $i; if ($number === 0) { continue; } if ($i) { $ret .= Dictionary::$wordSeparator; } if ($power - 1) { $ret .= $this->showDigitsGroup($number, Dictionary::$exponent[($power - 1) * 3]); } else { $showedNoun = true; $ret .= $this->showDigitsGroup($number, $noun, false, $num !== 1); } } if (!$showedNoun) { $ret .= Dictionary::$wordSeparator . $this->getNounDeclensionForNumber('m', $noun); // ALWAYS many } return trim($ret, Dictionary::$wordSeparator); }