DELIMITER //

drop function if exists rdecimal;
CREATE FUNCTION rdecimal ( f float, p int )
RETURNS decimal(20,4)

SQL SECURITY INVOKER
BEGIN

   DECLARE ret DECIMAL(20,4);
	set ret = cast(round(f,p) as decimal(20,4));
   RETURN ret;

END; //

DELIMITER ;