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