Rounding to nearest nickel in RPG ILE

15 pts.
Tags:
AS/400
RPG ILE
Can anyone tell me how to round up to the nearest nickel in RPG ILE? My field is defined as 7.2.

Answer Wiki

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

Discuss This Question: 9  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
  • azohawk

    I havent had to do this, but I think that I would do something of this.

    Data structure

    d                        ds

    d fullamount                 7  2

    d dollars                       6  1  overlay(fullamount:1)

    d pennies                      1 0  overlay(fullamount:7)

    ....

    Select;

       When pennies <= 0 and  pennies >4;

                  pennies = 0;

        When pennies >= 4 and pennies <8;

                 pennies = 5;

        other;

                 pennies = 0;

                  dollars += .1;  //increment the dimes

          endsl;

     

    There may be better ways, but this seems pretty simple and straight forward to me. and the logic could be used in other languages. You may prefer different rounding points, but you can adjust for that.

    505 pointsBadges:
    report
  • azohawk
    I think I have a few < and > reversed, but follow the intent of getting the ranges.
    505 pointsBadges:
    report
  • philpl1jb

    Round1 = %Int(valueIn * 10) / 10  // value in 57.23 round1 = 57.20

    Pennies = valueIn - Round1         // pennies = 57.23-57.20 = 00.03

    Select

    when Pennies < 3

       Round1 = Round1 + .00

    when Pennies < 8

       Round1 = Round1 + .05

    other 

       Round1 = Round1 + .10

    endsl

    ----------

    A really good arguement for dropping the nickle when the penny is dropped.

    ----------------

    Hope this helps with your homework.

    50,205 pointsBadges:
    report
  • bvining
    Your subject line and question are not in agreement, so I'm not sure how to answer your request without additional information.

    The subject line is 'Rounding to nearest nickel' which often suggests that you want a penny value of 1, 2, 6, or 7 to decrease the amount by 1 or 2 pennies, otherwise add the necessary pennies to get to the next nickel value.

    The question text however is 'round up to the nearest nickel' which would suggest that you want any penny count that is not 0 or 5 to result in the addition of sufficient pennies to get/up the count to 0 or 5.

    Which is it? Obviously any answers you get right now are subject to how the responder interpreted your query.
    6,510 pointsBadges:
    report
  • aceofdelts

    Pennies divided by 5

    Round to nearest integer

    multiply by 5

    This is "round off".

    1,930 pointsBadges:
    report
  • carolm

    Rounding UP to the next nickel is what I needed.  I apologize for the confusion I created by using the word nearest in the subject.

     

    15 pointsBadges:
    report
  • philpl1jb
    So, were you able to resolve this issue?
    50,205 pointsBadges:
    report
  • aceofdelts

    OK - Round Up is ...

    Add 4 to pennies

    Divide by 5

    Truncate any remainder

    Multiply by 5

    done


    1,930 pointsBadges:
    report
  • aceofdelts

    also

    It gets vague if amount is negative because Up and Down become ambiguous

    1,930 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