How to capture decimal value of numeric fld

35 pts.
Tags:
RPG
I need a way to capture the decimal value of a numeric field (i.e. 5.78). Need a way to be able to break the decimal value away to do computations on it. How do I achieve this using RPG III coding techniques?

Software/Hardware used:
AS/400 I series

Answer Wiki

Thanks. We'll let you know when a new response is added.

What do you need to do with it? That may determine the best technique to use.

One way would be to use a data structure, another would be to z-add it to a field with with length/dec positions.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    It depends on exact circumstances, but using data structure subfields will get your exact requirement handled.   I DS I 1 53@CVT I 3 53@FRAC I DS I 1 33FRAC C Z-ADD5.78 @CVT C Z-ADD@FRAC FRAC C*** DO CALCS WITH FRAC... C SETON LR  Define the subfields to hold the largest numbers of digits, including fractional digits, that your program needs to handle. Make sure that the two intermediate subfields (@CVT and @FRAC) are defined as zoned decimal.   (We'll see how the "code" looks after it gets posted.)   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Well, sorry about the formatting. This editor makes very little sense.   The @CVT field is defined over positions 1-5 with 3 decimal fraction positions. It's zoned decimal. Both @FRAC and FRAC also have 3 decimal positions and are zoned decimal. @FRAC is defined starting position 3 of the DS because that's where the fractional portion of @CVT begins. @CVT is where your numeric value will be placed for conversion to just the fractional portion.   Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Or perhaps an EVAL statement like:DecVal = Val - %int(Val)
    50,205 pointsBadges:
    report
  • philpl1jb
    Oh sorry ... RPG III .. why would you do that?  Is this another interview question? .  But if you must, check out the DIV and MVR commands.  If you divide by 1 the Remainder (MVR) would be the decimal. 
    50,205 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following