browsing the internet I found a few solutions. While trying out the solutions, I combined some the ideas and found the following code works.
But is it efficient and is it a trustful solution? Basically casting a numeric type to an integer
CREATE OR REPLACE FUNCTION "convToInt"(valuearg character varying)
RETURNS integer AS
EXECUTE 'SELECT to_number(quote_literal($1), quote_literal(99999999))' INTO result
LANGUAGE plpgsql VOLATILE
ALTER FUNCTION "convToInt"(character varying)
OWNER TO postgres;