270 pts.
 Converting amount in character field to numeric in rpgle
Hi, How to convert the amount value in character field(Eg: ' 5,000- ') to numeric in rpgle. I used %DEC built in function, it shows decimal data error. Is there any bulit in function or opcode to convert ' 5,000- ' to numeric field in rpgle ?

Software/Hardware used:
i series V5R4M0
ASKED: October 8, 2012  11:04 AM

Answer Wiki:
You need two %Dec statements.  Amount$  = %Dec(%subst(iRec:1:1)  +                                    (%subst(iRec:3:04)) : 11 : 2);          
Last Wiki Answer Submitted:  October 8, 2012  1:57 pm  by  CharlieBrowne   32,885 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,885 pts. , LakNar   270 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

%DEC is the sorrect function and will convert

Fld1C = ’5000.00′.

Fld1N = %DEC(Fld1C : 6 ; 2).

But it will probably fail if there are commas in the input field.

It will fail if the input field isn’t convertable.

It will fail if the input field is null.

It will probably fail if the last character is a -.

To control the process,
Clean up the input
Put the function in a Monitor Block.

 44,190 pts.

 

Thanks for ur reply… But i need to convert this value( ‘ 5,000-’ ) as 5000- . How can i achieve this ?

 270 pts.

 

 

And I stand corrected .. the negative sign will not be an issue:
http://www.itjungle.com/fhg/fhg052009-story02.html
 

 44,190 pts.

 

The %DEC() function can be used on your example value as long as the thousands-separator is removed. Phil’s article link shows a way to do that. You could also use the Convert External Form to Numeric Value (CVTEFN) MI builtin directly. It allows thousands-separators. I’m not sure why %DEC() doesn’t simply call CVTEFN. — Tom

 108,135 pts.