1 views_handler_field_numeric.inc views_handler_field_numeric::render($values)

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides views_handler_field::render

File

core/modules/views/handlers/views_handler_field_numeric.inc, line 119
Definition of views_handler_field_numeric.

Class

views_handler_field_numeric
Render a field as a numeric value

Code

function render($values) {
  $value = $this->get_value($values);

  // Output nothing if the value is null.
  if (is_null($value)) {
    return '';
  }

  // Check to see if hiding should happen before adding prefix and suffix.
  if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
    return '';
  }

  if (!empty($this->options['set_precision'])) {
    $precision = $this->options['precision'];
  }
  elseif ($decimal_position = strpos($value, '.')) {
    $precision = strlen(rtrim($value, '0')) - $decimal_position - 1;
  }
  else {
    $precision = 0;
  }

  // Use round first to avoid negative zeros.
  $value = round($value, $precision);
  // Test against both integer zero and float zero.
  if ($this->options['empty_zero'] && ($value === 0 || $value === 0.0)) {
    return '';
  }

  $value = number_format($value, $precision, $this->options['decimal'], $this->options['separator']);

  // Should we format as a plural.
  if (!empty($this->options['format_plural'])) {
    $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']);
  }

  return $this->sanitize_value($this->options['prefix'], 'xss')
    . $this->sanitize_value($value)
    . $this->sanitize_value($this->options['suffix'], 'xss');
}