/** * Formats a NostoPrice object into a price string. * * @param NostoPrice $price the price object. * @param NostoPriceFormat|null $format the price format or null if default. * @return string the formatted price. */ public function format(NostoPrice $price, NostoPriceFormat $format = null) { if (is_null($format)) { $format = new NostoPriceFormat(2, '.', ''); } return number_format($price->getPrice(), $format->getDecimals(), $format->getDecimalPoint(), $format->getThousandsSeparator()); }
/** * Convert a price using given exchange rate. * * @param NostoPrice $price the price to convert into different currency. * @param NostoCurrencyExchangeRate $rate the currency exchange rate to use for the conversion. * @return NostoPrice the converted price. */ public function convert(NostoPrice $price, NostoCurrencyExchangeRate $rate) { $convertedPrice = $price->multiply($rate->getExchangeRate()); if ($convertedPrice->usingFractionUnits()) { $convertedPrice = new NostoPrice($convertedPrice->getRawPrice(), $rate->getCurrency()); } return $convertedPrice; }