Using floating point numbers in RPG: Difference between revisions
(New) |
(+Link) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Using ''' floating point numbers in RPG''' is not as straightforward as using character, or decimal fields. | 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. | 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. | ||
Line 19: | Line 19: | ||
Do not attempt to use <code>MOVE</code> for copying floating point data between variables. If you do, the compiler will give you error RNF7547. You must use <code>EVAL</code> as shown above.<ref>This raises questions about how to program with floating point variables in pre-ILE RPG.</ref> | Do not attempt to use <code>MOVE</code> for copying floating point data between variables. If you do, the compiler will give you error RNF7547. You must use <code>EVAL</code> as shown above.<ref>This raises questions about how to program with floating point variables in pre-ILE RPG.</ref> | ||
== See also == | |||
*[[Using timestamps in RPG]] | |||
== Weblinks == | == Weblinks == |
Latest revision as of 22:27, 23 February 2023
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
Footnotes
- ↑ This raises questions about how to program with floating point variables in pre-ILE RPG.