Formats an ISBN number.

@param string $isbn The ISBN-10 or ISBN-13 number.

@return string The formatted ISBN number.

@throws Exception\InvalidIsbnException If the ISBN is not valid.
17477
public function format(string $isbn) : string
    {
        if ($this->cleanupBeforeValidate) {
            if (preg_match(Internal\Regexp::ASCII, $isbn) === 0) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            $isbn = preg_replace(Internal\Regexp::NON_ALNUM, '', $isbn);
        }

        if (preg_match(Internal\Regexp::ISBN13, $isbn) === 1) {
            if ($this->validateCheckDigit) {
                if (! Internal\CheckDigit::validateCheckDigit13($isbn)) {
                    throw Exception\InvalidIsbnException::forIsbn($isbn);
                }
            }

            return Internal\RangeService::format($isbn);
        }

        $isbn = strtoupper($isbn);

        if (preg_match(Internal\Regexp::ISBN10, $isbn) === 1) {
            if ($this->validateCheckDigit) {
                if (! Internal\CheckDigit::validateCheckDigit10($isbn)) {
                    throw Exception\InvalidIsbnException::forIsbn($isbn);
                }
            }

            return Internal\RangeService::format($isbn);
        }

        throw Exception\InvalidIsbnException::forIsbn($isbn);
    }
696411
public static function dec2big(string $number): string
    {
    	static::checkExtensionOrFail();

        $alphabet = static::NUMBERS;
        $number = trim((string)$number);

        if (strlen($number) == 0) {
            throw new Exception('Got empty number for dec2big, can not proceed');
        }

        $mod = (string)count($alphabet);
        $s = '';

        do {
            $x = bcdiv($number, $mod, 0);
            $left = bcmod($number, $mod);
            $char = $alphabet[$left];
            $s = $char . $s;

            $number = $x;
        } while ($x != '0');

        return $s;
    }
560311
public static String isbn() {
        StringBuffer stringBuffer = new StringBuffer("09");
        stringBuffer.append(String.format("%06d", JDefaultNumber.randomIntBetweenTwoNumbers(0, 49999)));
        stringBuffer.append(String.format("%02d", JDefaultNumber.randomIntBetweenTwoNumbers(0, 99)));
        String numberString = stringBuffer.toString();


        int number = Integer.parseInt(numberString);
        int sum = 0;
        for (int i = 2; i <= 10; i++) {
            int digit = number % 10;                // rightmost digit
            sum = sum + i * digit;
            number = number / 10;
        }

        // Determine check digit, use X for 10
        String checkDigit = null;
        if (sum % 11 == 1) {
            checkDigit = "X";
        } else if (sum % 11 == 0) {
            checkDigit = "0";
        } else {
            checkDigit = (11 - (sum % 11)) + "";
        }

        //  System.out.println("The full ISBN number is " + numberString+checkDigit);
        String returnString = stringBuffer.toString();
        returnString = returnString.substring(0, 1) + "-" + returnString.substring(1, 7) + "-" + returnString.substring(7, 9) + "-" + checkDigit;

        return returnString;
    }
167099
public static function isValidISBN13($isbn)
    {
        $isbn = self::normalizeISBN($isbn);
        if (strlen($isbn) != 13) {
            return false;
        }
        return
            substr($isbn, 12) == self::getISBN13CheckDigit(substr($isbn, 0, 12));
    }
929018
public static String isbn13Format(final String pstring) {
    if (pstring == null) {
      return null;
    }
    final ValueWithPos<String> formatedValue = isbn13FormatWithPos(new ValueWithPos<>(pstring, -1));
    return formatedValue.getValue();
  }
938534
public static function assertNumberFormat($number)
    {
        if (is_float($number)) {
            throw new \InvalidArgumentException(sprintf('The provided value "%s" must be a string, not a float.', $number));
        }
        if (!is_numeric($number)) {
            throw new \InvalidArgumentException(sprintf('The provided value "%s" is not a numeric value.', $number));
        }
    }
1179534
public static function toNumbers($s){
		$ret = array();
		for($i=0; $i<strlen($s); $i+=2){
			$ret[] = hexdec(substr($s, $i, 2));
		}
		return $ret;
	}
210059
public static function withCheckDigitForIsbn10($isbn)
    {
        // Sanitize
        $isbn = preg_replace('/[^0-9]/', '', $isbn);
        $isbn = substr($isbn, 0, 9);

        // Validate
        if (strlen($isbn) != 9) {
            return null;
        }

        // Calculate (sum)
        $sum = 0;
        for ($i = 0; $i < 9; $i++) {
            $sum += (10 - $i) * $isbn{$i};
        }

        // Calculate (check digit)
        $checkDigit = 11 - ($sum % 11);
        $checkDigit = $checkDigit == 10 ? "X" : ($checkDigit == 11 ? 0 : $checkDigit);

        return $isbn . $checkDigit;
    }
1186382
public function numberFormat($decimals = 0, $thousandSeparator = '.', $decimalSeparator = ',')
    {
        $decimalSeparator = $thousandSeparator === '.' ? ',' : '.';

        return number_format($this->amount, $decimals, $decimalSeparator, $thousandSeparator);
    }
91407
public static function checkIsbn10Number($isbn)
    {
        $isbn = trim($isbn);
        if (mb_strlen($isbn) !== 10 || preg_match('/0{10}/', $isbn)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }

        $total = 0;
        for ($i = 0; $i < 9; $i++) {
            $digit = intval(substr($isbn, $i, 1));
            $total += ((10 - $i) * $digit);
        }

        $check_sum = (11 - ($total % 11)) % 11;
        if ($check_sum === 10) {
            $check_sum = 'X';
        }

        if ($check_sum != substr($isbn, 9)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }
    }
1164413
public static function getISBN13CheckDigit($isbn)
    {
        $sum = 0;
        $weight = 1;
        for ($x = 0; $x < strlen($isbn); $x++) {
            $sum += intval(substr($isbn, $x, 1)) * $weight;
            $weight = $weight == 1 ? 3 : 1;
        }
        $retval = 10 - ($sum % 10);
        return $retval == 10 ? 0 : $retval;
    }
694506
protected function _detectFormat()
    {
        // prepare separator and pattern list
        $sep      = quotemeta($this->_separator);
        $patterns = array();
        $lengths  = array();

        // check for ISBN-10
        if ($this->_type == self::ISBN10 || $this->_type == self::AUTO) {
            if (empty($sep)) {
                $pattern = '/^[0-9]{9}[0-9X]{1}$/';
                $length  = 10;
            } else {
                $pattern = "/^[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9X]{1}$/";
                $length  = 13;
            }

            $patterns[$pattern] = self::ISBN10;
            $lengths[$pattern]  = $length;
        }

        // check for ISBN-13
        if ($this->_type == self::ISBN13 || $this->_type == self::AUTO) {
            if (empty($sep)) {
                $pattern = '/^[0-9]{13}$/';
                $length  = 13;
            } else {
                $pattern = "/^[0-9]{1,9}[{$sep}]{1}[0-9]{1,5}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1}$/";
                $length  = 17;
            }

            $patterns[$pattern] = self::ISBN13;
            $lengths[$pattern]  = $length;
        }

        // check pattern list
        foreach ($patterns as $pattern => $type) {
            if ((strlen($this->_value) == $lengths[$pattern]) && preg_match($pattern, $this->_value)) {
                return $type;
            }
        }

        return null;
    }
827665
public function identify($isbn)
    {
        if($this->is10($isbn) === true) {
            return 10;
        }
        
        return ($this->is13($isbn) === true ? 13 : false);
    }
1142080
public static function php_number_format($number)
    {

        preg_match('/[.,](\d+)$/', $number, $matches);

        $num_decimals = strlen($matches[1]);

        return preg_replace('/[.,]/', '', $number) / pow(10, $num_decimals);
    }
550487
public function setNumber($number)
    {
        if (!is_numeric($number) && $number != null)
        {
            throw new InvalidArgumentException("Number is not numeric.");
        }
        $this->number = preg_replace('/\D/', '', $number);
    }
155930
public static function format($number, $decimals = 2, $decimalPoint = '.', $thousandSeparator = ',')
    {
        return number_format($number, $decimals, $decimalPoint, $thousandSeparator);
    }
266740
public static function of(string $isbn) : Isbn
    {
        if (preg_match(Internal\Regexp::ASCII, $isbn) === 0) {
            throw Exception\InvalidIsbnException::forIsbn($isbn);
        }

        $isbn = preg_replace(Internal\Regexp::NON_ALNUM, '', $isbn);

        if (preg_match(Internal\Regexp::ISBN13, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit13($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, true);
        }

        $isbn = strtoupper($isbn);

        if (preg_match(Internal\Regexp::ISBN10, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit10($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, false);
        }

        throw Exception\InvalidIsbnException::forIsbn($isbn);
    }