Feed on
Subscription

Decimal precision is handled in business system, round, abandon completely, the method of complete carry

In business system, different client has differring method to decimal processing

Pass the decimal digit that withholds in the setting, and decimal digit is the following the processing technique of mantissa, OK and agile contented client asks

Processing technique watch

ID NUMBER(1) , - - install ID

AMOUNTDOT NUMBER(4, 2) DEFAULT 0.01, - - amount accuracy 1: Arrive accurately yuan 0.1: ??returns ?of the Nbsp; 0.01: that irrigate ?? returns OUNDING of ? of any of several hot spice plants NUMBER(1) , - - rounding off dividing line - - 9: Abandon completely 0: Enter completely 4: ?ccept ? is entered

Build ORACLE function, pass into setting ID, pass into amount, return treated amount

Memory process realizes code to be as follows

Create Or Replace Function Get_Real_Number ( - - according to processing technique ID, the amount after obtaining processing - calculative amount
ID IN NUMBER, - - processing technique IDN_Amount IN NUMBER)
-----------------------------------------------------------------------
- - With Road From the definition data precision is handled.
- - The person that found :Andrew
-----------------------------------------------------------------------
- - Modification record list:(those who press date go against foreword to arrange orderly early or late)
- - Modification time Modification person The function of implementation explains
- - 9 is abandoned completely 0 is entered completely 4 four abandon 5 into
-----------------------------------------------------------------------Return NUMBER- - returned amount
ISV_amountdot VARCHAR2(5); - - decimal digit characterV_keep NUMBER; - - the decimal digit of reservationV_rounding NUMBER; - - rounding off dividing lineV_Amount NUMBER:=0; - - returned amount
BEGIN

SELECT Amountdot, nvl(rounding, 0) INTO V_amountdot, processing technique of V_rounding FROM is expressed
WHERE Id = SALE_PLACE_ID;V_keep:=Length(v_amountdot) - Instr(v_amountdot, ' . ') ; - - the decimal digit that wants reservation
IF V_rounding = 9 THEN - - processing is abandoned completelyV_Amount:=Trunc(n_Amount, v_keep);
END IF;

IF V_rounding = 4 THEN - - handle to the nearest whole numberV_Amount:=Round(n_Amount, v_keep);
END IF;

IF V_rounding = 0 THEN - - handle complete carryV_Amount:=Trunc(n_Amount, v_keep); - - several what decimal amount to just is equal to a requirement to withhold
IF V_Amount %26lt;%26gt;N_Amount THEN - - if the number after intercept and original figure are different, into 1V_Amount:=V_Amount + To_number(v_amountdot);
END IF;

RETURN V_Amount;

ExceptionWhen OTHERS Then RETURN N_Amount;

END Get_Real_Number;


Related:

收藏到网摘:

Submit: