You are here

function webform_modulo in Webform 7.4

Same name and namespace in other branches
  1. 6.3 components/number.inc \webform_modulo()
  2. 7.3 components/number.inc \webform_modulo()

Custom modulo function that properly handles float division.

See https://drupal.org/node/1601968.

1 call to webform_modulo()
_webform_validate_number in components/number.inc
A Drupal Form API Validation function.

File

components/number.inc, line 905
Webform module number component.

Code

function webform_modulo($a, $b) {

  // Ensure values are either int or float.
  if (!is_numeric($a) || !is_numeric($b)) {
    return 0.0;
  }
  $a = +$a;
  $b = +$b;
  $modulo = $a - $b * ($b < 0 ? ceil($a / $b) : floor($a / $b));
  if (webform_compare_floats($modulo, 0.0) == 0 || webform_compare_floats($modulo, $b) == 0) {
    $modulo = 0.0;
  }
  return $modulo;
}