|
How many different scenarios are you attempting to accommodate?
The way you have it coded you need to change the code for each and every
scenario so I'd be inclined to take a simpler approach that avoids
multiplication altogether.
Something like:
Ctl-Opt DftActgrp( *No );
Dcl-Ds convertIt;
number zoned(15:5);
char char(15) SamePos(number);
End-Ds;
dcl-s myNumber1 packed(7:2) inz(12345.67);
dcl-s myNumber2 packed(9:4) inz(12345.6789);
number = myNumber1;
Dsply ( '#1 is: *' + char + '*');
number = myNumber2;
Dsply ( '#2 is: *' + char + '*');
*InLr = *On;
This is not _the_ answer but it might get you thinking. If you enclosed
this in a subprocedure and fed it the decpos etc. as a parm it would be
quite simple to make it generic.
It won't work for negative numbers but ...
Jon Paris
Jon.Paris@xxxxxxxxxxxxxx
On Jun 17, 2025, at 2:55 PM, David Gibbs via RPG400-L <rpg400-l@xxxxxxxxxxxxxxxxxx> wrote:
related questions.
Folks:
I'm in the process of creating a routine that needs to adjust
different sized numeric fields to be whole integers.
To do this, I'm multiplying the value times 10 raised to the number of
decimal positions.
So, if I have 12345.67, I multiply by 100 and get 1234567.
To make this easily adaptable, I use the %DECPOS bif to get the number
of decimal positions.
For example:
dcl-s digits2 zoned(20:2) inz(1234567.89);
result = digits2 * (10 ** %decpos(digits2));
The problem is, if the number of decimal positions is 2, the
calculation isn't working correctly.
In the above case, the result is 123456788.
HOWEVER, if I use %int on the result of the multiplier, I do get the
correct result.
result = digits2 * %int(10 ** %decpos(digits2));
This results in 123456789.
As best as I can determine, the result of the '10 ** %decpos(digits2)'
is a float and is causing a rounding error of some sort.
Here's a sample program that you can step through in the debugger.
https://code.midrange.com/ad462aef4a.html
Any thoughts?
Thanks!
david
--
IBM i on Power Systems: For when you can't afford to be out of business!
I'm riding in the American Diabetes Association's Tour de Cure to
raise money for diabetes research, education, advocacy, and awareness.
You can make a tax-deductible donation to my ride by visiting
https://mideml.diabetessucks.net.
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.