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.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.