You are here

class CurrencyFormatter in Price 3.x

Same name and namespace in other branches
  1. 8 src/CurrencyFormatter.php \Drupal\price\CurrencyFormatter
  2. 2.0.x src/CurrencyFormatter.php \Drupal\price\CurrencyFormatter
  3. 2.x src/CurrencyFormatter.php \Drupal\price\CurrencyFormatter
  4. 3.0.x src/CurrencyFormatter.php \Drupal\price\CurrencyFormatter

Extends the commerceguys/intl CurrencyFormatter to provide better defaults.

Hierarchy

  • class \Drupal\price\CurrencyFormatter extends \CommerceGuys\Intl\Formatter\CurrencyFormatter

Expanded class hierarchy of CurrencyFormatter

See also

\CommerceGuys\Intl\Formatter\CurrencyFormatterInterface

1 string reference to 'CurrencyFormatter'
price.services.yml in ./price.services.yml
price.services.yml
1 service uses CurrencyFormatter
price.currency_formatter in ./price.services.yml
Drupal\price\CurrencyFormatter

File

src/CurrencyFormatter.php, line 15

Namespace

Drupal\price
View source
class CurrencyFormatter extends ExternalCurrencyFormatter {

  /**
   * Constructs a new CurrencyFormatter object.
   *
   * @param \CommerceGuys\Intl\NumberFormat\NumberFormatRepositoryInterface $number_format_repository
   *   The number format repository.
   * @param \CommerceGuys\Intl\Currency\CurrencyRepositoryInterface $currency_repository
   *   The currency repository.
   * @param \Drupal\price\CurrentLocaleInterface $current_locale
   *   The current locale.
   */
  public function __construct(NumberFormatRepositoryInterface $number_format_repository, CurrencyRepositoryInterface $currency_repository, CurrentLocaleInterface $current_locale) {
    $default_options = [
      'locale' => $current_locale
        ->getLocale()
        ->getLocaleCode(),
      // Show prices as-is. All digits (storage max is 6), non-rounded.
      'maximum_fraction_digits' => 6,
      'rounding_mode' => 'none',
    ];
    parent::__construct($number_format_repository, $currency_repository, $default_options);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrencyFormatter::__construct public function Constructs a new CurrencyFormatter object.