On 2025-06-17 2:55 p.m., David Gibbs via RPG400-L wrote:
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.


You can use a procedure with OPTIONS(*CONVERT) to do this easily.

dcl-s intval int(20);
dcl-s decval packed(7:2) inz(12345.67);

p1 (5.7);
p1 (123.45678);
p1 (-123.45678);
p1 (1234567890123132142331434.2352562366);

// Test it for real
intval = p1 (decval);
snd-msg 'intval is ' + %char(intval);

return;

dcl-proc p1;
dcl-pi *n packed(63);
val varchar(65) const options(*convert);
end-pi;
dcl-s temp varchar(65);
dcl-s retval packed(63);
temp = %scanrpl('.' : '' : val);
retval = %dec(temp : 63 : 0);
snd-msg 'Input: ' + val + ' Output ' + %char(retval);
return retval;
end-proc;

The procedure is doing a snd-msg on its parameter and return value. Here's what it shows in the joblog after. First the output from the procedure and then the snd-msg from the "real test".

Input: 5.7 Output 57
Input: 123.45678 Output 12345678
Input: -123.45678 Output -12345678
Input: 1234567890123132142331434.2352562366 Output
12345678901231321423314342352562366
Input: 12345.67 Output 1234567
intval is 1234567


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