round up with decimals [ 901 views ]
Goal: to create a function to round up numbers with decimals
We need to round up every numbers for a catalog view. May be with decimals or without.
CREATE OR REPLACE FUNCTION Roundup(p_number IN NUMBER, p_pos IN NUMBER DEFAULT 0) RETURN NUMBER IS --> 1.00 - 2009.03.09. - init version l_result NUMBER; BEGIN l_result := ROUND(p_number, p_pos); IF (l_result < p_number) THEN l_result := l_result + (1/POWER(10,p_pos)); END IF; RETURN l_result; END; The result: select roundup(10.123,0) from dual; --> 11 select roundup(10.123,1) from dual; --> 10.2 select roundup(10.123,2) from dual; --> 10.13 select roundup(10.123,3) from dual; --> 10.123