× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



" That's because it wasn't there."

I guess that's a matter of interpretation. As the title indicates, the OP wanted to "round up".




-----Original Message-----
From: John Yeung [mailto:gallium.arsenide@xxxxxxxxx]
Sent: Wednesday, February 12, 2020 4:01 PM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: What is a good way to round up numbers in free form?

On Wed, Feb 12, 2020 at 3:30 PM Booth Martin <booth@xxxxxxxxxxxx> wrote:

I missed the "always round up" part.

That's because it wasn't there. OP probably just wanted the standard half-adjust, which is handled with the (h) extender, per your original suggestion.

What they did say was that what they had been doing so far "wasn't rounding up". It was just a description of the observed behavior, which is different than saying that they want the opposite. In other words, the (r) extender was not doing any rounding up at all, even though they wanted *some* numbers to round up.

Justin took it and ran with it, and it's a nice mental exercise to see how you *would* always round up (not just at half and above). So, for the rest of this e-mail, let's assume we want to always round up to the nearest whole penny. One "micro-cent" should round up to one cent.

try this:

eval(h) result = (qty * price) + .005;

That should also to the trick.

Not quite. If (qty * price) happens to come out to an exact number of cents, like 0.70, then after rounding, the result should still be 0.70. But doing it as you've shown gives us 0.71 instead.

John Y.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.