Converting amount in character field to numeric in rpgle

270 pts.
Tags:
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

You need two %Dec statements.

 Amount$  = %Dec(%subst(iRec:1:1)  +                   
                (%subst(iRec:3:04)) : 11 : 2);          

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    %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.
    50,860 pointsBadges:
    report
  • LakNar
    Thanks for ur reply... But i need to convert this value( ' 5,000-' ) as 5000- . How can i achieve this ?
    270 pointsBadges:
    report
  • philpl1jb
    50,860 pointsBadges:
    report
  • philpl1jb
    And I stand corrected .. the negative sign will not be an issue: http://www.itjungle.com/fhg/fhg052009-story02.html  
    50,860 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following