Link to home
Start Free TrialLog in
Avatar of dpalme
dpalme

asked on

Extract decimal portion of a numeric variable

If if I have a numeric data type that has an initial value of say 123.98, is there an easy way to extract the .98 portion of that data type?

ASKER CERTIFIED SOLUTION
Avatar of Barry Harper
Barry Harper
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpalme
dpalme

ASKER

what is the 52 and 22 values you have at the far right of both c-specs?

Avatar of dpalme

ASKER

I tried the following and received an error that the receiver value is to small to hold the result:

 6       C                   EVAL      MYNBR = 123.98    
 7       C                   MOVE     mynbr         mydec
Those are the variable length and number of decimal places.  N22 and N52 are variable names (I should have used better names!)  It is clearer if prompted using F4:

 Prompt type . . .    C      Sequence number . . .  0001.00            
                                                                       
 Level    N01N02N03  Factor 1     Operation      Factor 2     Result  
                                                   Z-ADD        123.98       N52      
             Decimal                                                  
 Length     Positions    H/N/P   HI   LO   EQ    Comment              
    5           2    

and

 Prompt type . . .    C      Sequence number . . .  0002.00            
                                                                       
 Level    N01N02N03  Factor 1     Operation      Factor 2     Result  
                                                   MOVE         N52          N22      
             Decimal                                                  
 Length     Positions    H/N/P   HI   LO   EQ    Comment              
    2           2                                                                        

You can cut and paste the original c-specs above into an RPG member to check them out as well.

Barry                              
Avatar of dpalme

ASKER

I have even tried to specify the length and decimal positions on the cspec without any success:

0004.01 Dmydec            S              2  2                            
0005.00 C                   EVAL      MYNBR = 123.98                    
0005.01 C                   MOVE      mynbr         mydec             2 2
Avatar of dpalme

ASKER

never mind I found the problem....I was not compiling the module first and so even though the source was changed the program still wasn't being changed.

I switched my example to RPGLE using your variables:

Dmynbr            S              5  2                              
Dmydec            S              2  2                              
C                   EVAL      mynbr = 123.98                        
C                   MOVE      mynbr         mydec                  
C     mydec         DSPLY                                          
C                   SETON                                        LR
C                   RETURN                                          

When I run this code, mydec contains .98 as needed. What is happening in your case?
Barry


Good! Glad you got to the bottom of it!