(Re)Calculate check digit of given $ean and return complete ean with (new) check digit.

@param int $ean

@return string|null
506291
public static function withCheckDigitForEan($ean)
    {
        // Sanitize
        $ean = (int) $ean;
        $ean = substr($ean, 0, 12);

        // Validate
        if (strlen($ean) != 12) {
            return null;
        }

        // Calculate (sum)
        $sum = 0;
        for ($i = 0; $i < 12; $i++) {
            $sum += $ean{$i} * ($i % 2 ? 3 : 1);
        }

        // Calculate (check digit)
        $checkDigit = ceil($sum / 10) * 10 - $sum;

        return $ean . $checkDigit;
    }
811059
public function getEan8() : ?string 
    {
        if ( ! $this->hasEan8()) {
            $this->setEan8($this->getDefaultEan8());
        }
        return $this->ean8;
    }
1260697
public static function isValid(string $number) : bool
    {
        if (ctype_digit($number)) {
            return self::checksum($number) === 0;
        }

        return false;
    }
883062
public static function ceil($number)
    {
        if (self::compare($number, 0) == 1) {
            $result = bcadd($number, '1', 0);
        } else {
            $result = bcadd($number, '0', 0);
        }

        return $result;
    }
242049
public function revokeNumberAsyncWithHttpInfo($number)
    {
        $returnType = '';
        $request = $this->revokeNumberRequest($number);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
501187
protected function calculateChecksum() {
        // Calculating Checksum
        // Consider the right-most digit of the message to be in an "odd" position,
        // and assign odd/even to each character moving from right to left
        // Odd Position = 3, Even Position = 9
        // Multiply it by the number
        // Add all of that and do ?mod10
        $odd = true;
        $this->checksumValue = 0;
        $c = strlen($this->text);
        for ($i = $c; $i > 0; $i--) {
            if ($odd === true) {
                $multiplier = 3;
                $odd = false;
            } else {
                $multiplier = 9;
                $odd = true;
            }

            if (!isset($this->keys[$this->text[$i - 1]])) {
                return;
            }

            $this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
        }

        $this->checksumValue = $this->checksumValue % 10;
    }
741199
private function roundDigit(Number $number)
    {
        if ($number->isCloserToNext()) {
            return bcadd(
                (string) $number,
                $number->getIntegerRoundingMultiplier(),
                0
            );
        }

        return bcadd((string) $number, '0', 0);
    }
78175
def calculate_check_digit(gtin):
    ''''''
    reverse_gtin = gtin[::-1]
    total = 0
    count = 0
    for char in reverse_gtin:
        digit = int(char)
        if count % 2 == 0:
            digit = digit * 3
        total = total + digit
        count = count + 1

    nearest_multiple_of_ten = int(math.ceil(total / 10.0) * 10)

    return nearest_multiple_of_ten - total
957395
public static function convert($number)
    {
        $number = preg_replace('/\,/i', '', $number);

        $number = preg_replace('/([^0-9\.\-])/i', '', $number);

        if (! is_numeric($number)) {
            return '0.00';
        }

        $isCents = (bool) preg_match('/^0.\d+$/', $number);

        return ($isCents ? '0' : null).number_format($number * 100., 0, '.', '');
    }
950415
private static function getIbanLength($iban)
    {
        $countrycode = substr($iban, 0, 2);

        $lengths = array(
            'AL' => 28,
            'AD' => 24,
            'AT' => 20,
            'AZ' => 28,
            'BH' => 22,
            'BE' => 16,
            'BA' => 20,
            'BR' => 29,
            'BG' => 22,
            'CR' => 21,
            'HR' => 21,
            'CY' => 28,
            'CZ' => 24,
            'DK' => 18,
            'DO' => 28,
            'TL' => 23,
            'EE' => 20,
            'FO' => 18,
            'FI' => 18,
            'FR' => 27,
            'GE' => 22,
            'DE' => 22,
            'GI' => 23,
            'GR' => 27,
            'GL' => 18,
            'GT' => 28,
            'HU' => 28,
            'IS' => 26,
            'IE' => 22,
            'IL' => 23,
            'IT' => 27,
            'JO' => 30,
            'KZ' => 20,
            'XK' => 20,
            'KW' => 30,
            'LV' => 21,
            'LB' => 28,
            'LI' => 21,
            'LT' => 20,
            'LU' => 20,
            'MK' => 19,
            'MT' => 31,
            'MR' => 27,
            'MU' => 30,
            'MC' => 27,
            'MD' => 24,
            'ME' => 22,
            'NL' => 18,
            'NO' => 15,
            'PK' => 24,
            'PS' => 29,
            'PL' => 28,
            'PT' => 25,
            'QA' => 29,
            'RO' => 24,
            'SM' => 27,
            'SA' => 24,
            'RS' => 22,
            'SK' => 24,
            'SI' => 19,
            'ES' => 24,
            'SE' => 24,
            'CH' => 21,
            'TN' => 24,
            'TR' => 26,
            'AE' => 23,
            'GB' => 22,
            'VG' => 24,
            'DZ' => 24,
            'AO' => 25,
            'BJ' => 28,
            'BF' => 27,
            'BI' => 16,
            'CM' => 27,
            'CV' => 25,
            'IR' => 26,
            'CI' => 28,
            'MG' => 27,
            'ML' => 28,
            'MZ' => 25,
            'SN' => 28,
            'UA' => 29
        );

        return isset($lengths[$countrycode]) ? $lengths[$countrycode] : false;
    }
1337035
public function getNumeric($varname)
    {
        $value = $this->getString($varname);
        return is_numeric($value) ? $value + 0 : null;
    }
907743
function parseDSN($dsn) {
	 	if (is_array($dsn)) {
			return $dsn;
		} else {
		 	$dsn_match = "|^(?P<phptype>.*?)://(?P<parameters>.*?)/(?P<db>.*?)$|i";
		 	$parameter_match = "|^(?P<username>.*?):(?P<password>.*?)@(?P<hostspec>.*?)$|i";
		 	$args_match = '|^(?P<database>.*?)\?(?P<args>.*?)$|';

		 	/* First, pick out the phptype, database, and gunk in the middle */
			preg_match($dsn_match,$dsn,$matches['base']);
			/* Next, parse the gunk in the middle into username, host, and password */
			if (!empty($matches['base']['parameters'])) { preg_match($parameter_match,$matches['base']['parameters'],$matches['parameters']); }
			/* Then, parse the database to see if any commandline parameters were passed */
			if (substr_count($matches['base']['db'],"?") > 0) { preg_match($args_match,$matches['base']['db'],$matches['args']); }

			$retn = array();
			$retn['phptype'] = $matches['base']['phptype'];
			if (!empty($matches['base']['parameters']) && is_array($matches['parameters'])) {
			 	$retn['username'] = $matches['parameters']['username'];
			 	$retn['password'] = $matches['parameters']['password'];
			 	$retn['hostspec'] = $matches['parameters']['hostspec'];
			}
			if (!empty($matches['args']) && is_array($matches['args'])) {
			 	$retn['database'] = $matches['args']['database'];
			 	$retn['args'] = $this->parseDSN_args($matches['args']['args']);
			} else {
			 	$retn['database'] = $matches['base']['db'];
			}
			return $retn;
		}
    }
420319
function check(AE $e) {return
		dfa_flatten(array_map(function(R $r) use($e) {
			/** @var true|Phrase|Phrase[] $messages */
			$messages = $r->check($e);
			return true === $messages ? [] : df_array($messages);
		}, $this->_children)) ?: true
	;}
743709
public static function toIsbn10($ean, $onError = null)
    {
        // Sanitize
        $ean = preg_replace('/[^0-9]/', '', $ean);

        // Validate
        if (!preg_match('/^978(\d{9})\d?$/', $ean, $found)) {
            return $onError;
        }

        // Convert
        $isbn = $found[1];
        $isbn = static::withCheckDigitForIsbn10($isbn);

        return $isbn ?: $onError;
    }
526203
public function numToAlpha($n)
  {
    for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) {
      $r = chr($n%26 + 0x61) . $r;
    }
    return $r;
  }
733958
public function findByNumber($className, $number)
    {
        $extendee = trim($className, '\\');

        if ( ! isset($this->extensions[$extendee][$number])) {
            return null;
        }

        return $this->extensions[$extendee][$number];
    }
252644
public static function ordinal($number)
    {
        $test_c = abs($number) % 10;
        $ext = ((abs($number) % 100 < 21 && abs($number) % 100 > 4) ? 'th' : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1) ? 'th' : 'st' : 'nd' : 'rd' : 'th'));

        return $number . $ext;
    }