Jump to content

Hi all, For a retail pricing model I am trying to work out a...


Sarah Banks

Recommended Posts

Hi all,

For a retail pricing model I am trying to work out a formula that will round the last number of a D12.2 value UP to the nearest 5 or 9.

For example:

656.47 goes to 656.49

681.72 goes to 681.75

684.56 goes to 684.59

723.97 goes to 723.99

780.41 goes to 780.45

809.45 stays at 809.45

837.24 goes to 837.25

970.11 goes to 970.15

952.99 stays at 952.99

I am using App Studio version 8203

Link to comment
Share on other sites

It would make sense to build this into a DEFINE FUNCTION. For the calculations you could use the following. Run it to see that it works:

DEFINE FILE ibisamp/ggsales

ANUMBER/P20.2 = DECODE SEQ_NO ( 1 656.47

2 681.72

3 684.56

4 723.97

5 780.41

6 809.45

7 837.24

8 970.11

9 952.99 );

BNUMBER/P20.2 = ( ANUMBER * 10 - INT(ANUMBER * 10) ) / 10;

CNUMBER/P20.2 = IF BNUMBER LE .05 THEN .05 - BNUMBER ELSE .09 - BNUMBER;

ROUNDUP/P20.2 = ANUMBER + CNUMBER;

END

 

TABLE FILE ibisamp/ggsales

PRINT SEQ_NO ANUMBER BNUMBER CNUMBER ROUNDUP

WHERE SEQ_NO LE 9;

END

 

You should probably stick with packed decimal for these calculations.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...