The 'atoi' and 'atof' C functions handle conversion from numbers
containing decimal points and signs. If the number may contain a
decimal point, use 'atof' (it doesn't allow comma - you'd have to xlate
',':'.') Be sure to use half-adjust with atof because the result is
floating-point. Here's an example.
h bnddir('QC2LE')
D atoi pr 10i 0 extproc('atoi')
D num * options(*string) value
D atof pr 8f extproc('atof')
D num * options(*string) value
D i s 10i 0
D p s 13p 7
C movel '-100 ' num 6
C eval i = atoi(%trim(num))
* > EVAL i
* I = -100
C eval(h) p = atof(%trim(num))
* > EVAL i
* P = -000100.0000000
C movel '-5.67 ' num 6
C eval(h) p = atof(%trim(num))
* > EVAL p
* P = -000005.6700000
C return
Barbara Morris
IBM Toronto Lab
RPG Compiler Development
No reason to use C, when you've got RPG....
Example #1 - Packed Numeric to Alpha: Use the Z-ADD opcode to
decompress the packed field, and then the MOVE opcode to place it ito a
same sized alpha field.
C*
C* FIELDA = 7,0(P) FIELDB = 7,0(S) FIELDC = 7(A)
C*
C Z-ADD FIELDA FIELDB
C MOVE FIELDB FIELDC
C*
Example #2 - Zoned Decimal with two decimal places to a Character
field.
C*
C* FIELDA = 7,2(S) FIELDB = 7,0(S) FIELDC = 7A
C*
C FIELDA MULT 100 FIELDB
C MOVE FIELDB FIELDC
C*
Example #3 - Character field to Zoned Decimal with two decimal places.
C*
C* FIELDA = 7(A) FIELDB = 7,0(S) FIELDC = 7,2(S)
C*
C MOVE FIELDA FIELDB
C FIELDB MULT .01 FIELDC
C*
Jerry Collins [MISJGC@marsh.net]