You are here

function vap_num in Views Aggregator Plus 8

Same name and namespace in other branches
  1. 7 views_aggregator_functions.inc \vap_num()

Function to extract a double from a string, auto-skipping non-numeric chars.

Commas and spaces are ignored. Scientific notation, e.g., 1.23E-45, is NOT supported, it will return 1.23

Parameters

string $string: A string representatin of a double-precision floating point number.

Return value

mixed Returns double or FALSE, if no number could be found in the string.

4 calls to vap_num()
views_aggregator_average in ./views_aggregator_functions.inc
Aggregates a field group as the average amongst its members.
views_aggregator_median in ./views_aggregator_functions.inc
Aggregates a field group as the median across its members.
views_aggregator_percentage in views_aggregator_more_functions/views_aggregator_more_functions.module
Aggregates a field group total as the percentage of the column total.
views_aggregator_sum in ./views_aggregator_functions.inc
Aggregates a field group as the sum of its members.

File

./views_aggregator_functions.inc, line 724
views_aggregator_functions.inc

Code

function vap_num($string) {

  // Strip out any spaces and thousand makers.
  $stripped = str_replace([
    ' ',
    ',',
  ], '.', $string);
  $dots_count = substr_count($stripped, '.');
  if ($dots_count > 1) {

    // Leave last dot as decimal separator, get rid of the rest.
    $stripped = preg_replace('/\\./', '', $stripped, $dots_count - 1);
  }
  $value = preg_match('/[-+]?\\d*\\.?\\d+/', $stripped, $matches) ? (double) $matches[0] : FALSE;
  return $value;
}