I have a situation in which I always need to round a decimal up to the next integer. How would I accomplish this? Eval (h) won't do it, and I was just wondering if there was anything I could do short of writing my own logic that would accomplish this? A biff? Or opcode? or extender?
Announcement
Collapse
No announcement yet.
Round up to next integer
Collapse
X
-
Re: Round up to next integer
%inth or %dech
Code:HowmanyB = %inth(((TotalB * (364/Bdays)/50) * workweeks)); if %dech(((TotalB * (364/Bdays)/50) * workweeks):15:5) > *zeros and %dech(((TotalB * (364/Bdays)/50) * workweeks):15:5) < 1; HowmanyB += 1; endif;
All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
-
Re: Round up to next integer
No dice Jamie, I need it to ALWAYS round up. For example...
123.789 needs to round to 124
123.234 needs to round to 124 as well.
I think my only solution might be to do something like this....
Code:myrem = %rem(field1:field2); if myrem <> 0; mydecfld = field1/field2; myintfld = mydecfld + 1; endif;
Comment
-
Re: Round up to next integer
bryce thats what my code above does..
jamieAll my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Round up to next integer
yes just use mine as an example....did you notice that I can change the size of the dec field to 15,5 or whatever on the fly.All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Round up to next integer
Something isn't working there Jamie.
When I'm running it in debug mode and I do an F11 on the %dech() calls it tells me that a Syntax error occurred and won't give me the value. So it never goes into the if statement. What could be wrong? Do you have to store the value in a variable and then use that in the logic statement?
Comment
-
Re: Round up to next integer
Bryce:
Add .9999 to your calc. FastOne's solution will half round .9999 will round up (use as many 9s as you decimal position will go out to)
Best of Luck
GLSThe problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln
Comment
-
Re: Round up to next integer
I forgot bout that Birgitta thanks for the reminder....@#%@#%@#%@#% Im old
jamieAll my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: Round up to next integer
Originally posted by bryce4president View PostI'd still like to find an RPG solution, just in case I need it sometime.
Code:D DS D myNumber 15S 5 D myInteger 10S 0 Overlay(myNumber) D myDecimal 5S 5 Overlay(myNumber : *Next) /free myNumber = (field1 / field2); If (myDecimal > *Zeros); myInteger += 1; EndIf;
Comment
Comment