× 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.



"RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> wrote on 02/11/2020
08:50:35 PM:
I need to multiply qty (9,0) by money(8,3) giving a result with 2
decimal
places.

I tried eval(r) but it is not rounding the values. Result is (9,2). So
far
my results are not rounding up.

I would not like to code a subroutine to round these values and so am
asking
if I missed a way to do that or what is a best practice to do this?


EVAL(h) should do that. However, this may be considered overkill,
but I created a service procedure to give us complete flexibility in
rounding.


**************************************************************************

* This procedure rounds the passed number to the specified number of *

* decimal positions as the returned result. Maximum result decimals is *

* nine and that is the default. For normal rounding (where .4 or below *

* rounds down while .5 or above rounds up) do not pass the third parm. *

* Optionally, pass the maximum decimal value to round down. Examples: *

* .9 always rounds down, .0 always rounds up, and .4 is normal rounding. *

**************************************************************************

dcl-proc GenUtl_roundDecimal export;

dcl-pi *n packed(31:9);

pNumber packed(33:11) const;

pDecimals uns(3) const options(*nopass:*omit);

pRoundAt packed(1:1) const options(*nopass);

end-pi;



dcl-s adjustBy int(10:0);

dcl-s iRoundBy packed(1:1) inz(.5);



if %parms() < %parmnum(pDecimals) // if parm not passed
or %addr(pDecimals) = *null // or it was omitted
or pDecimals > 9; // or is greater than internal limit
adjustBy = 10 ** 9; // default adjust by internal limit
else; // else
adjustBy = 10 ** pDecimals; // adjust by decimal positions specified

endif;



if %parms() < %parmnum(pRoundAt) // if parm not passed
or %addr(pRoundAt) = *null; // or it was omitted
else; // use default rounding, else
iRoundBy = .9 - %abs(pRoundAt); // calculate the rounding factor
endif;



return (%int(pNumber * adjustBy + iRoundBy) / adjustBy); // return
rounded value
end-proc;



Sincerely,

Dave Clark

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.