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

%REM will return an integer.

You can multiply both factors by 100,1000,10000 and divide the result by the same number
Answer = %REM( A*100 : B*100)/100
so if A= 2.5421 and B = 2
the %REM(254.21 : 200) /100 = .54

or

Result = %int(A/B)
Remainder = A – (Result * B)

Phil

%REM will return an integer.
You can multiply both factors by 100,1000,10000 and divide the result by the same number
Answer = %REM( A*100 : B*100)/100
so if A= 2.5421 and B = 2
the %REM(254.21 : 200) /100 = .54
or
Result = %int(A/B)
Remainder = A - (Result * B)
Phil

Please enter an answer.

Send me notifications when members answer or reply to this question.

Register Here or login if you are already a member

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

Improve This Answer

Improve This Answer

Processing your response...

Discuss This Question: 2 Replies

There was an error processing your information. Please try again later.

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

Please enter a reply.

Send me notifications when members answer or reply to this question.

Register Here or login if you are already a member

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

%REM is accepting only interger values.
...Which is as it should do. Note that the related %DIV() BIF is also an integer function.
While the MVR op-code would 'work' with decimal fractions, you should understand that it is a relatively expensive arithmetic operation. Division of decimal fractions at the binary/bit level is imprecise. Decimal fractions generally do not have precise binary equivalents. Under the covers, the same thing happens with the DIV and MVR op-codes as Phil recommends in his Answer. The values are adjusted to be integers in order to preserve accurate "remainders".
This is a part of the fundamental incompatibility between the decimal fractions that we (humans) use and the binary representations that computers use.
Try expressing a simple ".3" as a binary fraction for example. That might give you an idea of the difficulties involved.
It might appear as if you are drastically slowing down your calculations, but it really doesn't make that much difference when you need to capture a fractional remainder.
Ideally, you would use redefined variables at the start, and eliminate the need for the "multiply both factors by 100, etc." piece.
Tom

ohhhhh..that was a senior moment -- parameters need to be integer .. guess I had a flash of fmod -- from the C math stuff which you could use in RPGLE.
But, to finally answer your question.
Remainder = %REM(%INT(Premium) : %INT(Instalments))
or if you need remainder to 2 decimals
Remainder = %REM(%INT(Premium*100) : %INT( Instalments *100))/100
Yes, that will burn a few cycles, but what are a few cycles between friends.
The concept that modulus should be based on integers appears to date to the early 1800;s.
Phil

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

Reply

Processing your reply...

Ask a Question

Question Title:(150 char. limit.) Question:(Please be specific.)

Free Guide: Managing storage for virtual environments

Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!

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

Follow

Thanks! We'll email you when relevant content is added and updated.

## Discuss This Question: 2 Replies

Register Here

or login if you are already a member

%REM is accepting only interger values....Which is as it should do. Note that the related %DIV() BIF is also an integer function. While the MVR op-code would 'work' with decimal fractions, you should understand that it is a relatively expensive arithmetic operation. Division of decimal fractions at the binary/bit level is imprecise. Decimal fractions generally do not have precise binary equivalents. Under the covers, the same thing happens with the DIV and MVR op-codes as Phil recommends in his Answer. The values are adjusted to be integers in order to preserve accurate "remainders". This is a part of the fundamental incompatibility between the decimal fractions that we (humans) use and the binary representations that computers use. Try expressing a simple ".3" as abinaryfraction for example. That might give you an idea of the difficulties involved. It might appear as if you are drastically slowing down your calculations, but it really doesn't make that much difference when you need to capture a fractional remainder. Ideally, you would use redefined variables at the start, and eliminate the need for the "multiply both factors by 100, etc." piece. Tom