Sign in

docs RPG Reference

Guidelines for Choosing the Numeric Format for a Field

Guidelines for Choosing the Numeric Format for a Field

Guidelines for Choosing the Numeric Format for a Field

You should specify the integer or unsigned format for fields when:

  • Performance of arithmetic is important

    With certain arithmetic operations, it may be important that the value used be an integer. Some examples where performance may be improved include array index computations and arguments for the built-in function %SUBST.

  • Interacting with routines written in other languages that support an integer data type, such as ILE C®. may contain values above 9999 or 999999999.

Packed, zoned, and binary formats should be specified for fields when:

  • Using values that have implied decimal positions, such currency values
  • Manipulating values having more than 19 digits
  • Ensuring a specific number of digits for a field is important

Float format should be specified for fields when:

  • The same variable is needed to hold very small and/or very large values that cannot be represented in packed or zoned values.

However, float format should not be used when more than 16 digits of precision are needed.

Note: Overflow is more likely to occur with arithmetic operations performed using the integer or unsigned format, especially when integer arithmetic occurs in free-form expressions. This is because the intermediate results are kept in integer or unsigned format rather than a temporary decimal field of sufficient size.