Reputation: 787
I have a PF in a rpgle program with a field having values 1001.123, 1001.234, 1001.561 and so on. I need to capture the number after the decimal position for doing some calculations. So I need to fetch 123 from 1001.123 , get 234 from 1001.234 and so on.
Can some one tell me how to achieve this in RPGLE?
Upvotes: 0
Views: 564
Reputation: 7648
It could be done with a data structure as well
**free
dcl-ds *n;
your_var zoned(10: 3);
your_decimals zoned(3: 0) pos(8);
end-ds;
dcl-s msg char(50);
your_var = 1001.123;
msg = %trim(%char(your_var)) + '=>' + %trim(%char(your_decimals));
dsply msg;
*inlr = *on;
Upvotes: 1
Reputation: 3212
If what you want is an unsigned integer, you can do it like this, provided the integer part of your_var
fits in a int(10)
.
decimals = %int((your_var - %int(your_var)) * 10 ** %decpos(your_var))
If performance is critical and your_var is defined as packed(7:3)
then this would be better
decimals = %abs(your_var - %dec(your_var:7:0)) * 1000.0;
Upvotes: 3
Reputation: 1074
Get the whole number using %dec with 0 decimal and substract it from your var:
your_var - %dec(your_var : 0 )
Upvotes: 0