CREATE OR REPLACE FUNCTION public.round_half_down (numeric,integer) RETURNS numeric AS $body$ DECLARE arg ALIAS FOR $1; rnd ALIAS FOR $2; tmp1 numeric; res numeric; vra varchar; inta integer; ifa boolean; BEGIN tmp1:= arg; vra := substr(cast((arg - floor(arg)) as varchar),3); ifa := null; FOR i IN 1 .. length(vra) LOOP inta := CAST((substr(vra,i,1)) as integer); IF (i > rnd) THEN IF ((ifa is null) AND inta >= 6)THEN ifa := true; ELSE ifa := false; END IF; END IF; END LOOP; IF ifa THEN res:=trunc(arg,rnd); ELSE res:=round(arg,rnd); END IF; RETURN res; END; END; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER COST 100;
Sabtu, 28 September 2013
Round Half Down
Buat teman-teman yang ingin membuat function untuk posgres round half down semoga ini bisa membantu :
Langganan:
Postingan (Atom)