You are here

function webform_modulo in Webform 7.3

Same name and namespace in other branches
  1. 6.3 components/number.inc \webform_modulo()
  2. 7.4 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. Validates the entered values from number components on the client-side form.

File

components/number.inc, line 822
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;
  return $a - $b * ($b < 0 ? ceil($a / $b) : floor($a / $b));
}