pdval -- Packed Decimal Conversion: Packed Decimal to Double

SYNOPSIS
#include <packed.h>
double pdval(const char (*val)[], unsigned int scale);
DESCRIPTION
pdval
converts val
, a number in packed-decimal format, to its
floating-point representation. The maximum length of val
is 8
bytes (15 decimal digits). After conversion, val
is multiplied by
pow(10.0, -scale)
. scale
, which specifies a scaling factor,
must be a nonnegative integer less than or equal to 15.
RETURN VALUE
The return value is the double-precision, floating-point representation
of val
, appropriately scaled.
ERRORS
If val
does not contain valid packed-decimal data, an 0C7 ABEND
results.
DIAGNOSTICS
If scale
is not positive and less than or equal to 15, then pdval
returns HUGE_VAL
and sets errno
to EARG.
IMPLEMENTATION
pdval
is defined in <packed.h>
as
#define pdval(val, scale) _pdval(val, sizeof(*val), scale)
EXAMPLE
#include <packed.h>
#include <stdio.h>
void printamt(char (*amount)[6])
/* expected COBOL data declaration: */
/* AMOUNT PIC 9(9)V99 COMP-3. */
{
double dollars;
/* Convert to dollars and cents. */
dollars = pdval(amount, 2);
printf("Amount is $ % 12.2fn", dollars);
return;
}
RELATED FUNCTIONS
pdset
SEE ALSO