Swat/SwatString.php
public static function toInteger($string)
    {
        $lc = localeconv();

        $string = self::parseNegativeNotation($string);

        // change all locale formatting to numeric formatting
        $remove_parts = array(
            $lc['positive_sign'] => '',
            $lc['thousands_sep'] => ''
        );

        $value = str_replace(
            array_keys($remove_parts),
            array_values($remove_parts),
            $string
        );

        // note: This might be done better with a regexp, though
        // checking too closely how well a number matches its locale
        // formatting could become annoying too. i.e. if 1000 was
        // rejected because it wasn't formatted 1,000

        if (is_numeric($value)) {
            if ($value > (float) PHP_INT_MAX) {
                throw new SwatException(
                    'Floating point value is too big to be an integer'
                );
            }

            if ($value < (float) (-PHP_INT_MAX - 1)) {
                throw new SwatException(
                    'Floating point value is too small to be an integer'
                );
            }

            $value = intval($value);
        } else {
            $value = null;
        }

        return $value;
    }
public static function toInteger($string)
    {
        $lc = localeconv();

        $string = self::parseNegativeNotation($string);

        // change all locale formatting to numeric formatting
        $remove_parts = array(
            $lc['positive_sign'] => '',
            $lc['thousands_sep'] => ''
        );

        $value = str_replace(
            array_keys($remove_parts),
            array_values($remove_parts),
            $string
        );

        // note: This might be done better with a regexp, though
        // checking too closely how well a number matches its locale
        // formatting could become annoying too. i.e. if 1000 was
        // rejected because it wasn't formatted 1,000

        if (is_numeric($value)) {
            if ($value > (float) PHP_INT_MAX) {
                throw new SwatException(
                    'Floating point value is too big to be an integer'
                );
            }

            if ($value < (float) (-PHP_INT_MAX - 1)) {
                throw new SwatException(
                    'Floating point value is too small to be an integer'
                );
            }

            $value = intval($value);
        } else {
            $value = null;
        }

        return $value;
    }
public static function toInteger ( $ string ) { $ lc = localeconv ( ) ; $ string = self :: parseNegativeNotation ( $ string ) ; // change all locale formatting to numeric formatting $ remove_parts = array ( $ lc [ 'positive_sign' ] => '' , $ lc [ 'thousands_sep' ] => '' ) ; $ value = str_replace ( array_keys ( $ remove_parts ) , array_values ( $ remove_parts ) , $ string ) ; // note: This might be done better with a regexp, though // checking too closely how well a number matches its locale // formatting could become annoying too. i.e. if 1000 was // rejected because it wasn't formatted 1,000 if ( is_numeric ( $ value ) ) { if ( $ value > ( float ) PHP_INT_MAX ) { throw new SwatException ( 'Floating point value is too big to be an integer' ) ; } if ( $ value < ( float ) ( - PHP_INT_MAX - 1 ) ) { throw new SwatException ( 'Floating point value is too small to be an integer' ) ; } $ value = intval ( $ value ) ; } else { $ value = null ; } return $ value ; }
Convert a locale-formatted number and return it as an integer.

If the string can not be converted to an integer, the method returns
null. If the number has values after the decimal point, the value is
rounded according to the rounding rules for PHP's
{@link http://php.net/manual/en/function.intval.php intval} function.

If the number is too large to fit in PHP's integer range (depends on
system architecture), an exception is thrown.

@param string $string the string to convert.

@return integer the converted value or null if it could not be
converted.

@throws SwatException if the converted number is too large to fit in an
integer.
Convert a locale - formatted number and return it as an integer .