Announcement

Collapse
No announcement yet.

calculations with currency

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calculations with currency

    Code:
    FUNCTION CalcMatch(A1 AS STRING, B1 AS STRING) AS STRING
    LOCAL cA1,cB1,cMatch AS CURRENCY
    
        cA1 = VAL(A1) : cB1 = VAL(B1)
    
        'matching scenarios ladder up
        IF cB1 / cA1 <= 0.03# THEN '1st matching scenario
            FUNCTION = B1
            EXIT FUNCTION
        END IF
    
        IF cB1 / cA1 <= 0.05# THEN '2nd matching scenario
            cMatch = cA1 * 0.03# + cA1*(cB1/cA1-0.03#) * 0.5#
            FUNCTION = FORMAT$(cMatch,"#####.00")
            EXIT FUNCTION
        END IF
    
        cMatch = cA1 * 0.04# '3rd matching scenario
        FUNCTION = FORMAT$(cMatch,"#####.00")
    END FUNCTION
    For the most accurate results, should I change the numeric literals from DOUBLE to EXTENDED or CURRENCY, or is DOUBLE adequate?
    Erich Schulman (KT4VOL/KTN4CA)
    Go Big Orange

  • #2
    EXT would be the best choice.

    Comment


    • #3
      Erich, do you have PB 9/5? If so, then you can use eg. 0.03## to convert them to EXT.

      Comment


      • #4
        In the example given it's moot, since no intermediate value requires more than 4 positions after the decimal, meaning you never get into rounding at all.

        FWIW, I use CUR for all money stuff and never have any problems.

        [added]
        :doh: Except for the division.


        MCM
        Last edited by Michael Mattias; 24 Mar 2009, 07:48 PM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X