340 pts.
 How to convert a “Numeric-String” with ‘-’ sign and decimal places into pure “Numeric”?
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
ASKED: June 30, 2010  2:51 PM
UPDATED: July 5, 2010  10:15 PM

Answer Wiki:
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;
Last Wiki Answer Submitted:  June 30, 2010  4:36 pm  by  Rudedog   950 pts.
All Answer Wiki Contributors:  Rudedog   950 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

in COBOL, there is the intrinsic functions of NUMVAL and NUMVAL-C that will do the conversion for you in a single statement.

 880 pts.

 

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

 108,270 pts.