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