Using floating point numbers in RPG

From Try-AS/400
Jump to navigation Jump to search

Using floating point numbers in RPG is not as straightforward as using character, or decimal fields.

Not unlike date/time/timestamp fields, RPG has an internal way to handle those data types, which is incompatible with the external representation in externally described fields, such as database- and display files. While adding the internal date/time handling routines is a compile time option, this isn't the case for floating point operations.

Example

  • PF:
A            S_TEMPVAL      4F 1
  • DSPF:
A            S_TEMPVAL$     4Y 1O 16 52EDTCDE(P)
  • RPGLE:
C                   EVAL      S_TEMPVAL$ = S_TEMPVAL

Pitfalls

If you derive the DSPF field by referencing the PF field, the compiler will give you error RNF7452.

If you create an unreferenced DSPF field with type F, you'll get output in scientific notation with numbers and an exponent. If this isn't what you want, define the field as pure numeric F as shown in the example above.

Do not attempt to use MOVE for copying floating point data between variables. If you do, the compiler will give you error RNF7547. You must use EVAL as shown above.[1]

See also

Weblinks

  • RNF7452, IBM Rational Developer for i
  • RNF7547, IBM Rational Developer for i

Footnotes

  1. This raises questions about how to program with floating point variables in pre-ILE RPG.