[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Extract decimal portion of a numeric variable

Posted on 2006-05-25
Medium Priority
721 Views
Last Modified: 2012-05-05
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?

0
Question by:dpalme
• 4
• 4
8 Comments

LVL 13

Accepted Solution

_b_h earned 400 total points
ID: 16766430
Hi,
I usually just move it to a field with only decimal places. In this example, N52 is a numeric variable 5 digits long with 2 decimal places, and N22 is numeric variable 2 digits long with 2 decimal places:

C                     Z-ADD123.98    N52     52
C                     MOVE N52       N22     22

After the move N22 has the .98 value needed.

Barry
0

LVL 1

Author Comment

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

0

LVL 1

Author Comment

ID: 16766499
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
0

LVL 13

Expert Comment

ID: 16766520
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
0

LVL 1

Author Comment

ID: 16766521
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
0

LVL 1

Author Comment

ID: 16766530
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.

0

LVL 13

Expert Comment

ID: 16766559
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

0

LVL 13

Expert Comment

ID: 16766563
Good! Glad you got to the bottom of it!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multipleā¦
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
###### Suggested Courses
Course of the Month19 days, 13 hours left to enroll

#### 873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.