3 namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Form\FormStateInterface;
8 * Plugin implementation of the 'number_decimal' formatter.
10 * The 'Default' formatter is different for integer fields on the one hand, and
11 * for decimal and float fields on the other hand, in order to be able to use
15 * id = "number_decimal",
16 * label = @Translation("Default"),
23 class DecimalFormatter extends NumericFormatterBase {
28 public static function defaultSettings() {
30 'thousand_separator' => '',
31 'decimal_separator' => '.',
33 'prefix_suffix' => TRUE,
34 ] + parent::defaultSettings();
40 public function settingsForm(array $form, FormStateInterface $form_state) {
41 $elements = parent::settingsForm($form, $form_state);
43 $elements['decimal_separator'] = [
45 '#title' => t('Decimal marker'),
46 '#options' => ['.' => t('Decimal point'), ',' => t('Comma')],
47 '#default_value' => $this->getSetting('decimal_separator'),
50 $elements['scale'] = [
52 '#title' => t('Scale', [], ['context' => 'decimal places']),
55 '#default_value' => $this->getSetting('scale'),
56 '#description' => t('The number of digits to the right of the decimal.'),
66 protected function numberFormat($number) {
67 return number_format($number, $this->getSetting('scale'), $this->getSetting('decimal_separator'), $this->getSetting('thousand_separator'));