You are here

protected function Base::numberFormat in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/Base.php \Drupal\double_field\Plugin\Field\FieldFormatter\Base::numberFormat()

Formats a number.

2 calls to Base::numberFormat()
Base::prepareItems in src/Plugin/Field/FieldFormatter/Base.php
Prepare field items.
Base::settingsSummary in src/Plugin/Field/FieldFormatter/Base.php
Returns a short summary for the current formatter settings.

File

src/Plugin/Field/FieldFormatter/Base.php, line 344

Class

Base
Base class for Double field formatters.

Namespace

Drupal\double_field\Plugin\Field\FieldFormatter

Code

protected function numberFormat(string $subfield, string $number) : string {
  $settings = $this
    ->getSetting($subfield);
  if ($this
    ->getFieldSetting('storage')[$subfield]['type'] == 'integer') {
    $settings['scale'] = 0;
  }
  return number_format($number, $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);
}