# P2D (Packed-to-Decimal)

## Syntax:

    P2D(packnum[,scale][,synerrval])

## Arguments:

packnum
  the 1 to 8 byte packed decimal number to be converted. The number must be in packed format or an error will occur. See "Packed Format" below.
scale
  the number of digits to the right of the decimal point. If this argument is omitted a scale of 0 is assumed. The value for scale cannot exceed the number of decimal digits in packnum. The maximum value for scale is 15.
synerrval
  indicates the value to be returned if a syntax error is detected. This argument can be used to handle normally occurring invalid data. For example, null strings.

## Module Name:

SWXP2D

## Service Description:

The P2D function is used to convert packed decimal data into the REXX printable format. Since the System 370 packed decimal format does not include information regarding the location of the decimal point (if any), you must, if a decimal point is required, supply this information via the scale argument.

Note: P2D removes all leading zeros, except that a leading zero will be placed to the left of the decimal point if you specify a scale that is equal to the number of decimal digits in packnum.

## Packed Format:

Each byte of packed decimal data contains 2 decimal digits, except for the right-most byte which contains, in the left nibble, a decimal digit; and a sign designation in the right nibble ('C'X is positive; 'D'X is negative).

Notes:

1. The precision (i.e., the maximum number of digits) of a number is inferred from the number of bytes.
2. If the value of packnum is not a valid packed decimal number, the function call is in error.

## Returned Information:

The P2D function returns the REXX printable decimal representation of packnum. If you CALL the P2D function, the returned value is contained in the RESULT special variable. The RC special variable is unchanged.

## Examples:

1. Call the P2D function to convert the packed decimal number in PNUM. Since the value is in dollars, format the number with 2 decimal places:

       pnum = '1020000c'x
       salary = p2d(pnum,2)
       /* salary = 10200.00 */

© Copyright 1998 by Open Software Technologies, Inc.