/** * Gets the fractional part of the provided amount * * @param Amount $amount * * @return string */ protected function getFractionalPart(Amount $amount) { $number = new Number($amount->getNumber()->getSubunits()); //if the subunit format is numbers, we want to simply return a fraction if ($amount->getSubunitFormat()->getFormat() === SubunitFormat::NUMBERS) { return $number->getValue() . '/100'; } $unitName = $this->currencyDictionary->getSubunitName($amount->getCurrency(), !$this->isSingular($number)); return $this->numberTransformer->toWords($number) . ' ' . $unitName; }
/** * @param Amount $amount * * @return string */ public function toWords(Amount $amount) { $decimalPoint = '.'; $amountValue = round($amount->getNumber()->getValue(), 2); if (strpos($amountValue, $decimalPoint) === false) { return trim($this->toCurrencyWords($amount->getCurrency()->getIdentifier(), $amountValue)); } $currency = explode($decimalPoint, $amountValue, 2); $len = strlen($currency[1]); if ($len === 1) { $currency[1] .= '0'; } return $this->toCurrencyWords($amount->getCurrency()->getIdentifier(), $currency[0], $currency[1]); }
/** * Convert given number to words * * @param Amount $amount * * @return string */ public function toWords(Amount $amount) { $this->guardAgainstUnexistingCurrency($amount->getCurrency()); $unit = $this->toWordsWithGrammarCasedDescription($amount->getNumber(), CurrencyDictionary::getUnits()['PLN']); if ($amount->getSubunitFormat()->getFormat() === SubunitFormat::WORDS) { $subunit = $this->toWordsWithGrammarCasedDescription(new Number($amount->getNumber()->getSubunits()), CurrencyDictionary::getSubunits()['PLN']); } else { $subunit = sprintf('%d/100', $amount->getNumber()->getSubunits()); } return $unit . ' ' . $subunit; }