ifx_gl_convert_number - Convert a number string to an internal representation.
SYNOPSIS
#include <ifxgls.h>
int ifx_gl_convert_number(mi_decimal *money, char *decstr, char *format)
DESCRIPTION
This function converts the number string stored in decstr into
an internal representation. The internal representation is stored in
the mi_decimal structure pointed to by money in the format
specified by format.
If format is NULL, then the format is
determined from the LC_NUMERIC section of the current GLS locale.
If format is not NULL, then it must point to a string which
follows the rules described in the FORMAT section below.
FORMAT
The format is composed of white spaces, ordinary characters and one
conversion specification. One or more whitespaces in format
causes skipping over one or more whitespaces in decstr. Each
ordinary character in format is compared with that in
decstr. Any mismatch is reported as an error.
The conversion specification consists of a % character and a
terminating conversion character that determines the type of conversion,
with optional modifiers in between.
Only one conversion specification is allowed in format.
The following conversion specifications are supported.
- %b
- Matches a binary integer.
- %d, %i
- Matches a decimal integer.
- %e
- Matches a floating point number
- %E
- Same as in %e.
- %f
- Same as in %e.
- %g
- Same as in %e.
- %G
- Same as in %e.
- %o
- Matches an octal integer.
- %q
- Matches a base-4 integer.
- %u
- Matches an unsigned decimal integer.
- %x
- Matches a hexadecimal integer.
- %X
- Same as in %x.
If a conversion specification does not correspond to any of the above,
the behavior is undefined.
Modified Conversion Specifiers
Some conversion specifiers can be modified by putting modifier characters
between the % and the type specifier to indicate that an alternative format
is expected from decstr. The form of these modifiers is as follows.
[-][w][.p]
The square brackets indicate that the modifier is optional.
A minus sign directly after the % indicates that the first character
of decstr is expected to be the first character of the value to
be converted. Whitespace in decstr won't be skipped, but
reported as error.
w is a decimal value which specifies the maximum number of characters to
be read from decstr.
p is a decimal value that represents the minimum number of
characters that should be read. If less than p characters have been
read, it is considered to be an error unless there is left
justification, in which case trailing blanks are scanned over to read
the required number of characters.
RETURN VALUES
On success, this function returns 0.
On failure, this function returns -1.
ERRORS
If an error has occurred, this function returns -1 and
ifx_gl_lc_errno() returns,
- [IFX_GL_INVALIDFMT]
- The format control string 'format' is invalid.
- [IFX_GL_PARAMERR]
- The type specifier is invalid.
- [IFX_GL_ENOMEM]
- memory allocation failure.
SEE ALSO
ifx_gl_format_number(),
ACKNOWLEDGEMENT
Portions of this description were derived from the X/Open CAE
Specification: "System Interfaces and Headers, Issue 4"; X/Open
Document Number: C202; ISBN: 1-872630-47-2; Published by X/Open Company
Ltd., U.K.