create or replace function ftcm_roundmoney( adc_money number , as_satangtyp char , as_roundtyp char , ai_trunamt number , ai_roundamt number ) return number is ls_satangtyp char(2); ls_roundtyp char(1); li_trunamt number(1,0); li_roundamt number(1,0); ldc_fac number(3,2); ldc_rdamt number(3,2); ldc_point1 number(3,2); ldc_point2 number(3,2); ldc_integer number(20,7); ldc_money number(20,7); begin ldc_money := adc_money; ls_satangtyp := as_satangtyp; ls_roundtyp := as_roundtyp; li_trunamt := ai_trunamt; li_roundamt := ai_roundamt; dbms_output.put_line('satang_type='||ls_satangtyp); dbms_output.put_line('truncate_pos_amt='||li_trunamt); dbms_output.put_line('round_type='||ls_roundtyp); dbms_output.put_line('round_pos_amt='||li_roundamt); ldc_money := trunc( ldc_money , li_trunamt ); dbms_output.put_line('Money_trunc(0)='||ldc_money); for li_trunct in reverse li_roundamt..li_trunamt loop ldc_money := round( ldc_money , li_trunct ); dbms_output.put_line('Money_trunc('||li_trunct||')='||ldc_money); end loop; ldc_integer := trunc( ldc_money , 0 ); ldc_fac := ldc_money - ldc_integer; dbms_output.put_line('Fac='||ldc_fac); ldc_point1 := trunc( ldc_fac , 1 ); dbms_output.put_line('Point1='||ldc_point1); ldc_point2 := ldc_fac - ldc_point1; dbms_output.put_line('Point2='||ldc_point2); case ls_satangtyp when '00' then /*??????????*/ return ldc_money; when '10' then /*??????????? 5 ?????*/ if ldc_point2 = 0.00 or ldc_point2 = 0.05 then return ldc_money; elsif ldc_point2 >= 0.01 and ldc_point2 <= 0.04 then ldc_point2 := 0.05; elsif ldc_point2 >= 0.06 and ldc_point2 <= 0.09 then ldc_point2 := 0.1; end if; dbms_output.put_line('10Point1='||ldc_point1); dbms_output.put_line('10Point2='||ldc_point2); ldc_rdamt := ldc_point1 + ldc_point2; when '11' then /*??????????? 10 ?????*/ if ldc_point2 = 0.00 then return ldc_money; else ldc_point2 := 0.1; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '12' then /*??????????? 25 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.25 then ldc_rdamt := 0.25; elsif ldc_fac >= 0.26 and ldc_fac <= 0.50 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.51 and ldc_fac <= 0.75 then ldc_rdamt := 0.75; elsif ldc_fac >= 0.76 and ldc_fac <= 0.99 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '13' then /*??????????? 50 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.50 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.51 and ldc_fac <= 0.99 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '14' then /*??????????? 1 ???*/ if ldc_fac > 0.00 then ldc_rdamt := 1; else ldc_rdamt := 0; end if; when '48' then /* ?????? 5/4 ????0.05??? ??????? 0.05 ?????? ?????? 0.05 ?????? ??? 0.10 ??? */ if ldc_point2 < 0.05 then ldc_point2 := 0; elsif ldc_point2 = 0.05 then ldc_point2 := 0.05; else ldc_point2 := 1; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '49' then /* ?????? 5/4 ????1??? ??????? 0.50 ?????? ?????? 0.50 ?????? ?????????? */ if ldc_fac < 0.50 then ldc_rdamt := 0; else ldc_rdamt := 1; end if; when '50' then /*???????? 5 ?????*/ if ldc_point2 = 0.00 or ldc_point2 = 0.05 then return ldc_money; elsif ldc_point2 >= 0.01 and ldc_point2 <= 0.04 then ldc_point2 := 0.00; elsif ldc_point2 >= 0.06 and ldc_point2 <= 0.09 then ldc_point2 := 0.05; end if; dbms_output.put_line('51Point1='||ldc_point1); dbms_output.put_line('51Point2='||ldc_point2); ldc_rdamt := ldc_point1 + ldc_point2; when '51' then /*???????? 10 ?????*/ if ldc_point2 = 0.00 then return ldc_money; else ldc_point2 := 0.00; end if; ldc_rdamt := ldc_point1 + ldc_point2; when '52' then /*???????? 25 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.25 then ldc_rdamt := 0.00; elsif ldc_fac >= 0.26 and ldc_fac <= 0.50 then ldc_rdamt := 0.25; elsif ldc_fac >= 0.51 and ldc_fac <= 0.75 then ldc_rdamt := 0.50; elsif ldc_fac >= 0.76 and ldc_fac <= 0.99 then ldc_rdamt := 0.75; else ldc_rdamt := 0; end if; when '53' then /*???????? 50 ?????*/ if ldc_fac >= 0.01 and ldc_fac <= 0.50 then ldc_rdamt := 0.00; elsif ldc_fac >= 0.51 and ldc_fac <= 0.99 then ldc_rdamt := 0.50; else ldc_rdamt := 0; end if; when '54' then /*???????? 1 ???*/ ldc_rdamt := 0; else ldc_rdamt := ldc_fac; end case; ldc_integer := ldc_integer + ldc_rdamt; dbms_output.put_line('ldc_integer='||ldc_integer); dbms_output.put_line('ldc_rdamt='||ldc_rdamt); return ldc_integer; end ;