Возвращает отформатированную строку цены.

***

Returns a formatted price string.

@param Money $money
@param array $options
@param array $textOptions
@return string
@throws \yii\base\InvalidConfigException
351375
public function format(Money $money, $options = [], $textOptions = [])
    {
        return \Yii::$app->formatter->asCurrency($money->amount, $money->currency->code, $options, $textOptions);
    }
1348658
public static function moneyFormat($amount, $options = []) {
		$format = array_merge_hard(self::$options['locale_options'], $options['locale_options'] ?? []);
		$options['decimals'] = $options['decimals'] ?? 2;
		// sometimes symbols contain decimal point, we change it to thousands_sep
		if (!empty($options['symbol'])) {
			$options['symbol'] = str_replace($format['mon_decimal_point'], $format['mon_thousands_sep'], $options['symbol']);
		} else {
			$options['symbol'] = '';
		}
		// convert to string
		if (!is_string($amount)) {
			$amount = $amount . '';
		}
		$negative = strpos($amount, '-') !== false;
		$amount = ltrim($amount, '-');
		// if the number portion has been formatted
		if (empty($options['amount_partially_formatted'])) {
			$temp = explode('.', $amount);
			$number = $temp[0];
			$fraction = $temp[1] ?? '';
			// process number
			if (empty($number)) $number = '0';
			if ($format['mon_thousands_sep'] . '' !== '' && !empty($format['mon_grouping'])) {
				$counter = 0;
				$mon_grouping = [];
				$symbols = array_reverse(mb_str_split($number), true);
				$number = '';
				foreach ($symbols as $k => $v) {
					// grab group size
					if ($counter == 0) {
						if (empty($mon_grouping)) $mon_grouping = $format['mon_grouping'];
						if (count($mon_grouping) > 1) {
							$counter = array_shift($mon_grouping);
						} else {
							$counter = $mon_grouping[0];
						}
					}
					// skip number of characters
					$counter--;
					$number = $v . $number;
					if ($counter == 0 && $k > 0) {
						$number = $format['mon_thousands_sep'] . $number;
					}
				}
			}
			// left precision
			if (!empty($options['digits'])) {
				if (strlen($number) < $options['digits']) {
					$number = str_pad($number, $options['digits'], ' ', STR_PAD_LEFT);
				}
			}
			// right precision
			if ($options['decimals'] > 0) {
				$fraction = substr(str_pad($fraction, $options['decimals'], '0', STR_PAD_RIGHT), 0, $options['decimals']);
				$number = $number . $format['mon_decimal_point'] . $fraction;
			}
		} else {
			$number = $amount;
		}
		// translate characters
		$number = self::numberToFromNativeLanguage($number, $options);
		// format based on settings
		$cs_precedes = $negative ? $format['n_cs_precedes'] : $format['p_cs_precedes'];
		$sep_by_space = $negative ? $format['n_sep_by_space'] : $format['p_sep_by_space'];
		$sign_posn = $negative ? $format['n_sign_posn'] : $format['p_sign_posn'];
		// if accounting formatting
		if (!empty($options['accounting'])) {
			// if we have currency symbol we added it based on settings
			if (!empty($options['symbol'])) {
				$number = ($cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '')) : '') . $number . (!$cs_precedes ? (($sep_by_space === 1 ? ' ' : '') . $options['symbol']) : '');
			}
			if ($negative) {
				$number = '(' . $number . ')';
			} else {
				$number = ' ' . $number . ' ';
			}
		} else {
			$positive_sign = $format['positive_sign'];
			$negative_sign = $format['negative_sign'];
			$sign = $negative ? $negative_sign : $positive_sign;
			$other_sign = $negative ? $positive_sign : $negative_sign;
			$sign_padding = '';
			if ($sign_posn) {
				for ($i = 0; $i < (strlen($other_sign) - strlen($sign)); $i++) {
					$sign_padding.= ' ';
				}
			}
			$temp_value = '';
			switch ($sign_posn) {
				case 0: // parentheses surround value and currency symbol
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = '(' . $number . ')';
					break;
				case 1: // sign precedes
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = $sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $number;
					break;
				case 2: // sign follows
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = $number . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding;
					break;
				case 3: //sign precedes currency symbol
					$symbol = '';
					if (!empty($options['symbol'])) {
						$symbol = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '')) : (($sep_by_space === 2 ? ' ' : '') . $options['symbol']);
					}
					$number = $cs_precedes ? ($sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $symbol . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $sign . $sign_padding . $symbol);
					break;
				case 4: // sign succeeds currency symbol
					$symbol = '';
					$symbol_sep = '';
					if (!empty($options['symbol'])) {
						$symbol = $options['symbol'];
						$symbol_sep = ($sep_by_space === 1 ? ' ' : '');
					}
					$number = $cs_precedes ? ($symbol . ($sep_by_space === 2 ? ' ' : '') . $sign_padding . $sign . $symbol_sep . $number) : ($number . $symbol_sep . $symbol . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding);
					break;
			}
		}
		return $number;
	}
251714
public function currency($options = array())
    {
        $options = new AnConfig($options);

        $options->append(array(
            'name' => 'currency',
            'prompt' => true,
        ));

        $selected = $options->selected;
        unset($options->selected);
        $currencies = array_combine(self::$ISO_CURRENCY_SYMBOLS, self::$ISO_CURRENCY_SYMBOLS);

        return $this->_html->select($options->name, array('options' => $currencies, 'selected' => $selected), AnConfig::unbox($options));
    }
485375
public static function text($name, $value = '', array $htmlOptions = [])
    {
    	return self::input('text', $name, $value) . self::htmlOptions($htmlOptions) .'>';
    }
420504
public function getRate($currency = 'EUR')
    {
        $currency = mb_strtoupper($currency);
        if (array_key_exists($currency, $this->rates)) {
            return $this->rates[$currency];
        }
        throw new \InvalidArgumentException('Kurz pro měnu '.$currency.' neexistuje.');
    }
232810
public function &createOption($text = '', $value = '')
    {
        $option = $this->factory->create('Form\Checkbox');

        if ($text) {
            $option->setInner($text);
        }

        if ($value) {
            $option->setValue($value);
        }

        $this->controls[] = $option;

        return $option;
    }
1175511
public function price($name, $options = [])
    {
        $options['addon'] = ['before' => isset($options['currency']) ? $options['currency'] : 'Rp'];
        $options['class'] = isset($options['class']) ? $options['class'].' text-right' : 'text-right';

        return $this->text($name, $options);
    }
1302604
public function setOptions(array $options)
    {
        if(isset($options['exchange'])){
            if(!is_string($options['exchange'])){
                throw new \UnexpectedValueException('exchange value is not a string, a string is required');
            }
            $this->exchange = $options['exchange'];
            unset($options['exchange']);
        }
        if(isset($options['queue'])){
            if(isset($options['queue']['arguments'])){
                $this->queueOptions = $options['queue'];
            }
            unset($options['queue']);
        }
        $merged = array('uri' => isset($options['connection']) ? $options['connection'] : $this->options['uri']);
        $merge['options'] = array_merge($this->options['options'], (array) @$options['options']);
        $this->options = $merged;
        return $this;
    }
1193042
public function format(Int $money, String $type = NULL) : String
    {
        return Converter::money($money, $type);
    }
44708
public function toWords($amount, $currency, $options = null)
    {
        $dictionary = new EnglishDictionary();
        $numberToTripletsConverter = new NumberToTripletsConverter();
        $tripletTransformer = new EnglishTripletTransformer($dictionary);
        $exponentInflector = new EnglishExponentGetter();

        $numberTransformer = (new NumberTransformerBuilder())
            ->withDictionary($dictionary)
            ->withWordsSeparatedBy(' ')
            ->transformNumbersBySplittingIntoTriplets($numberToTripletsConverter, $tripletTransformer)
            ->useRegularExponents($exponentInflector)
            ->build();

        $decimal = (int) ($amount / 100);
        $fraction = $amount % 100;

        if ($fraction === 0) {
            $fraction = null;
        }

        $currency = strtoupper($currency);

        if (!array_key_exists($currency, EnglishDictionary::$currencyNames)) {
            throw new NumberToWordsException(
                sprintf('Currency "%s" is not available for "%s" language', $currency, get_class($this))
            );
        }

        $currencyNames = EnglishDictionary::$currencyNames[$currency];

        $return = trim($numberTransformer->toWords($decimal));
        $level = ($decimal === 1) ? 0 : 1;

        if ($level > 0) {
            if (count($currencyNames[0]) > 1) {
                $return .= ' ' . $currencyNames[0][$level];
            } else {
                $return .= ' ' . $currencyNames[0][0] . 's';
            }
        } else {
            $return .= ' ' . $currencyNames[0][0];
        }

        if (null !== $fraction) {
            $return .= ' ' . trim($numberTransformer->toWords($fraction));

            $level = $fraction === 1 ? 0 : 1;

            if ($level > 0) {
                if (count($currencyNames[1]) > 1) {
                    $return .= ' ' . $currencyNames[1][$level];
                } else {
                    $return .= ' ' . $currencyNames[1][0] . 's';
                }
            } else {
                $return .= ' ' . $currencyNames[1][0];
            }
        }

        return $return;
    }
611344
public function write($text, $option = [])
    {
        Output::write($this->format($text, $option));
        return $this;
    }
1196455
public function exchange(Money $money, $roundingMode = Money::ROUND_HALF_UP)
    {
        if ($money->getCurrency() != $this->getFromCurrency()) {
            throw new Exception\InvalidArgumentException('The Money has the wrong currency');
        }

        return $money->exchange($this->getToCurrency(), $this->getExchangeRate(), $roundingMode);
    }
487700
public static function createFromString(string $string): CurrencyPairContract
    {
        $matches = [];
        if (!preg_match('#^([A-Z0-9]{3,})\/([A-Z0-9]{3,})$#', $string, $matches)) {
            throw new \InvalidArgumentException('The currency pair must be in the form "EUR/USD".');
        }

        $parts = explode('/', $string);

        return new self($parts[0], $parts[1]);
    }
778582
public function option($text = null, $value = null, $selected = false)
    {
        return Option::create()
            ->text($text)
            ->value($value)
            ->selectedIf($selected);
    }
693651
public function formatMoney($amount, $currency = '€')
    {
        $symbols = array('€', '$', '£', '¥', '₤', 'kr', '₺');

        switch ($this->locale) {

            case 'de':
            case 'tr':
            case 'pt':
                $amount = number_format($amount, 2, ',', '.');
                $space = ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;

            case 'it':
            case 'nl':
                $amount = number_format($amount, 2, ',', '.');
                $space = ' ';
                $format = is_string($currency) ? $currency.$space.$amount : $amount;
                break;

            case 'fr':
                $amount = number_format($amount, 2, ',', ' ');
                $space = ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;            

            case 'ru':
                $amount = number_format($amount, 2, ',', ' ');
                $space = in_array($currency, $symbols) ? '' : ' ';
                $format = is_string($currency) ? $amount.$space.$currency : $amount;
                break;

            default:
            case 'en':
                $amount = number_format($amount, 2, '.', ',');
                $space = in_array($currency, $symbols) ? '' : ' ';
                $format = is_string($currency) ? $currency.$space.$amount : $amount;
                break;
        }

        return $format;
    }
1062370
protected function isCurrencyValid($currencyValue)
    {
        $availableCurrencies = $this->facade->getAvailableCurrencies();
        /** @var Currency $currency */
        $currencyFound = false;
        foreach ($availableCurrencies as $currency) {
            if ($currencyValue == $currency->getCode()) {
                $currencyFound = true;
            }
        }
        if (!$currencyFound) {
            throw new InvalidConditionValueException(
                \get_class(),
                'currency'
            );
        }

        return true;
    }
235606
public function charge($amount, array $options = array())
	{
		// $options = array_merge([
		// 	'currency' => $this->getCurrency(),
		// ], $options);
		
		$options['amount'] = $amount / 100;
		
		// if (! array_key_exists('source', $options) && $this->billable->hasBraintreeId()) {
		// 	$options['customer'] = $this->billable->getBraintreeId();
		// }
		
		// if (! array_key_exists('source', $options) && ! array_key_exists('customer', $options)) {
		// 	throw new InvalidArgumentException("No payment source provided.");
		// }
		
		// try {
			$response = BraintreeCharge::sale($options);
		// }
		// catch (StripeErrorCard $e) {
		// 	return false;
		// }
		
		return $response;
	}