You are here

protected function GeneralNumberFormatter::selectPrefix in Formatter Suite 8

Returns a prefix selected based on the value.

If there are less than 2 prefixes, the first one is always returned. Otherwise the singular or plural prefix is returned based upon the given value.

Parameters

mixed $number: The number to check for singular vs. plural.

array $prefixes: An array of 1 or 2 strings for singular and plural prefixes.

Return value

string Returns the chosen singular or plural prefix.

5 calls to GeneralNumberFormatter::selectPrefix()
GeneralNumberFormatter::numberFormatBasic in src/Plugin/Field/FieldFormatter/GeneralNumberFormatter.php
Formats a number using the basic set of formatting features.
GeneralNumberFormatter::numberFormatGeneral in src/Plugin/Field/FieldFormatter/GeneralNumberFormatter.php
Formats a number using the general set of formatting features.
GeneralNumberFormatter::numberFormatNumeral in src/Plugin/Field/FieldFormatter/GeneralNumberFormatter.php
Formats a number using a number system base.
GeneralNumberFormatter::numberFormatScientific in src/Plugin/Field/FieldFormatter/GeneralNumberFormatter.php
Formats a number using scientific notation.
GeneralNumberWithMinMaxFormatter::numberFormat in src/Plugin/Field/FieldFormatter/GeneralNumberWithMinMaxFormatter.php
Returns a formatted number, including min, max, prefix, and suffix.

File

src/Plugin/Field/FieldFormatter/GeneralNumberFormatter.php, line 977

Class

GeneralNumberFormatter
Format a number field with a variety of notation styles and parameters.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected function selectPrefix($number, array $prefixes) {
  if (count($prefixes) === 1) {
    return $prefixes[0];
  }
  return $this
    ->formatPlural($number, $prefixes[0], $prefixes[1]);
}