× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Booth,

C  eval   fee = $4.00 * ( 1 + ($650 / $500))
gives the result I want, excepting that $650/$500 is not 1.00

Dropping the decimals is easy with %INT or %DEC. However, this doesn't actually do what you want to do. For example:

     fee = 4.00 * ( 1 + %int(1000/500))

that'd give you $12.00 -- which is wrong.  $1000 should only be $8.

What you really want to do is add the extra 1 to the multiplier ONLY IF the result isn't an even multiple of 500. And that'll require an IF statement and therefore more than one line of code and a work variable.

Personally, I'd put this in a subprocedure and put that subprocedure in a service program. That way, you can write and test the logic once and then use it everywhere. Consideer the following:

     P CalcFee         B                   export
     D CalcFee         PI            11P 2
     D   total                       11P 2 value

     D rate            C                   const(4.00)
     D work            s             10I 0
     D fee             s             11P 2
      /free

          work = %int(total / 500);
          if (work * 500) < total;
             work = work + 1;
          endif;
          fee = work * rate;
          return fee;

      /end-free
     P                 E

Now whenever you want to calculate the fee, you can simply do this:

      fee = calcFee(totalDollars);

Since the same routine is used everywhere, when you want to change the logic, you go ahead and change the way it works and presto, everything is updated.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.