#include <packed.h> void pdset(char (*val)[], double input, unsigned int scale, double round);
pdset
converts input
to its packed-decimal representation.
input
is the double
value to be converted. val
is a
pointer to a character array in which the packed decimal result is
stored. The maximum size of val
is 8 bytes (15 decimal digits).
input
is multiplied by pow(10.0, scale)
before conversion.
scale
, which specifies a scaling factor, must be a positive
integer less than or equal to 15. round
is an amount added to
input
after scaling and before conversion. After round
is added,
any fractional portion is discarded.
pdset
has no return value.
input
value is the result of computations with nonintegral
data, a round
value of 0 is not recommended because it can cause
the effect of a small inaccuracy to be considerably magnified. For
example, with a scale
value of 2 and a round
of 0, a computed
value of 1.1699998 is stored as 116 (rather than 117).
pdset
sets the location pointed to by val
to all 9s (in packed-decimal format and with the appropriate sign) and
sets errno
to one of three values:
input
field is less than 8, errno
is set to
EUSAGE.
scale
is not less than or equal to 15, errno
is set to
EARG.
input
after scaling is too large to be converted,
errno
is set to ERANGE.
pdset
is defined in <packed.h>
as
#define pdset(val, input, scale, round)\ _pdset(val, sizeof(*(val)), input, scale, round)
#include <packed.h> pdstruct { char income[6]; char outgo[6]; /* expected COBOL data declarations: */ /* INCOME PIC 9(9)V99 COMP-3. */ /* OUTGO PIC 9(9)V99 COMP-3. */ } struct; void percent3(struct pdstruct *data) { double cents; cents = pdval(&data->income, 0); cents *= 0.03; /* Compute 3 percent. */ /* Store in record after rounding. */ pdset(&data->outgo, cents, 0, 0.5); return; }
pdval
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.