You are here

public function Formatter::number in Forena Reports 8

Format field as a number

Parameters

string $value:

string $format_string:

Return value

string

File

src/FrxPlugin/FieldFormatter/Formatter.php, line 175
contains various methods for extending report formating, layout, transformation and design.

Class

Formatter
Formatter for common drupal fields.

Namespace

Drupal\forena\FrxPlugin\FieldFormatter

Code

public function number($value, $format_string) {

  // Determine number nubmer formatter from the string.
  $chars = str_replace(array(
    '9',
    '0',
    '$',
  ), '', $format_string);
  if (strlen($chars) > 1) {
    $th_sep = substr($chars, 0, 1);
    $dec_sep = substr($chars, 1, 1);
    $dec_pos = strrpos($format_string, $dec_sep);
    if ($dec_pos) {
      $dec = strlen($format_string) - $dec_pos - 1;
    }
    else {
      $dec = 0;
      $dec_sep = '';
    }
  }
  elseif (strlen($chars) == 1) {
    $th_sep = substr($chars, 0, 1);
    $dec_sep = '';
    $dec = 0;
  }
  else {
    $dec_sep = '';
    $th_sep = '';
    $dec = 0;
  }
  if ($value && $this
    ->is_number($value)) {
    $value = number_format($value, $dec, $dec_sep, $th_sep);
  }
  return $value;
}