How to convert a “Numeric-String” with ‘-‘ sign and decimal places into pure “Numeric”?

620 pts.
Tags:
AS/400
OS/400
RPG ILE
String manipulation
Dear AS/400 Lovers! I need to convert a string containing Numeric-value with two-decimal places into a "Numeric". Alternatively the string may contain a minus-sign('-') in the beginning of the numeric-string(e.g. '-4321007.86'). The result should be pure numeric i.e. -4321007.86 The string's total length is 11-char, including minus-sign('-') & decimals. I tried using %TRIM and then %DEC on it to convert the same, but iam not getting the desired/expected result. Thanks a million in advance for your help. Svanky.

Software/Hardware used:
AS/400, OS/400, RPGILE

Answer Wiki

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

Svanky:

the code below works fine for me. it takes the 11 character string and converts it from
-1234567.89 to -001234567.89 numeric.

i verified this not only with using the DSPLY opcode but also with STRDBG and used F11 to view the actual value of field numeric.

-Sarge

d String s 11a Inz(‘-1234567.89′)
d Numeric s 11s 2

/free

Numeric = %Dec(String :11 :2);

dsply string;
dsply numeric;

*InLr = *On;

Discuss This Question: 2  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
  • NullFields
    in COBOL, there is the intrinsic functions of NUMVAL and NUMVAL-C that will do the conversion for you in a single statement.
    880 pointsBadges:
    report
  • TomLiotta
    I tried using %TRIM and then %DEC on it to convert the same, but iam not getting the desired/expected result. Have you solved your problem? Did the example work for you? If not, you need to show us how you tried to use %TRIM and %DEC. Without seeing your code, there is no way to help you correct the problem. 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