How to show/hide the prefix/suffix for fields? Sometimes in theming I want to programmatically hide the prefix or suffix of numeric fields. How can I do so?
When you look at the code of the numeric field formatter:

NumericFormatterBase::viewElements

  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    $settings = $this-&gt;getFieldSettings();

    foreach ($items as $delta =&gt; $item) {
      $output = $this-&gt;numberFormat($item-&gt;value);

      // Account for prefix and suffix.
      if ($this-&gt;getSetting('prefix_suffix')) {
        $prefixes = isset($settings['prefix']) ? array_map(['Drupal\Core\Field\FieldFilteredMarkup', 'create'], explode('|', $settings['prefix'])) : [''];
        $suffixes = isset($settings['suffix']) ? array_map(['Drupal\Core\Field\FieldFilteredMarkup', 'create'], explode('|', $settings['suffix'])) : [''];
        $prefix = (count($prefixes) &gt; 1) ? $this-&gt;formatPlural($item-&gt;value, $prefixes[0], $prefixes[1]) : $prefixes[0];
        $suffix = (count($suffixes) &gt; 1) ? $this-&gt;formatPlural($item-&gt;value, $suffixes[0], $suffixes[1]) : $suffixes[0];
        $output = $prefix . $output . $suffix;
      }
      // Output the raw value in a content attribute if the text of the HTML
      // element differs from the raw value (for example when a prefix is used).
      if (isset($item-&gt;_attributes) &amp;&amp; $item-&gt;value != $output) {
        $item-&gt;_attributes += ['content' =&gt; $item-&gt;value];
      }

      $elements[$delta] = ['#markup' =&gt; $output];
    }

    return $elements;


You see three things, first this is fully configurable, so it has not to happen in the first place, second it's hard to change afterwards, because the field content and the prefix/suffix is concatenated into one string and third you can get the raw values without prefix/suffix from the items attribute content:

field--field-number.html.twig

&lt;h3&gt;Field raw values:&lt;/h3&gt;
&lt;ul&gt;
  {% for item in items %}
    &lt;li&gt;{{ item.attributes.content }}&lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;