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

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

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

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

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

report
• I think I have a few < and > reversed, but follow the intent of getting the ranges.
report
• 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.

report

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.
report
• Pennies divided by 5

Round to nearest integer

multiply by 5

This is "round off".

report
• 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.

report
• So, were you able to resolve this issue?
report
• OK - Round Up is ...

Divide by 5

Truncate any remainder

Multiply by 5

done