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



Adam,

Not sure if that is completely true. Consider the following.

Done s 5 3 inz(60)
Dtwo s 5 3 inz(84)
Dfinal s 5 3
Drem s 5 3
C one div two final
C mvr rem
C eval *inlr=*on

When completed, rem = 00.024

This isn't the same as %DIV & %REM...

Crispin.

----- Original Message ----- From: "Adam Glauser" <adamglauser@xxxxxxxxxxxx>
Newsgroups: midrange.rpg400-l
To: <rpg400-l@xxxxxxxxxxxx>
Sent: Wednesday, January 30, 2008 1:44 PM
Subject: Re: Question about DIV and MVR


Ala, Michael A wrote:
Question about MVR operation how should the Div Result be Defined with
or without decimals

Same for Remainder Field

I have come up with various results with different formatting and want
to know best/Common practices

Example 60/84 = .714 on a calculator but one of programmers was not
getting this result with the move remainder when Both Fields were
defined with 3 decimal Places

MVR doesn't give you the decimal part of a non-integer quotient, it
gives the remainder. Integer division is defined by the formula:
a = qb + r where 0 <= r < b
In your case, a = 60, b=84, so q must be 0 and r must be 64.

Also, you should consider using the %div() and %rem() built-in functions
instead of DIV and MVR.

Perhaps you really want to
EVAL ratio = field1 / field2?
EVAL decimalPart = ratio - %div(field1:field2)

or, you could use DIV twice, once with a result field that has decimals
(a) and one that doesn't (b). Then, a - b should give you the decimal
part of the result.
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.