Conversion and formatting with Informix GLS

The library provides functions that allow you to perform the conversion and formatting tasks on locale-specific data.

Conversion
Changes a string that contains locale-specific formats to the internal representation of its value.

You usually perform conversion on a locale-specific string to prepare it for storage in a program variable or a database column.

Formatting
Changes the internal representation of a value to a locale-specific string.

You usually perform formatting of a locale-specific string to prepare the internal representation of a value for display or printing to the end user.

The internal representation of a value is one that can be stored directly in a database column. The following table lists the SQL data types for the internal representations along with the ESQL/C and DataBlade® API data types that hold these internal representations.
Type of data SQL data type ESQL/C data type DataBlade API data type
Numeric DECIMAL

SMALLINT, INTEGER, INT8, FLOAT, SMALLFLOAT

decimal (dec_t) mi_decimal
Monetary MONEY decimal (dec_t) mi_decimal
Date DATE date (long int) mi_date
Date and time DATETIME datetime (dtime_t) mi_datetime
Numeric data types: Numeric data includes integer, floating-point, and fixed-point numbers. The conversion and formatting functions represent all these numeric data types with the decimal (or mi_decimal) data type. To convert the decimal (or mi_decimal) representation to an integer or floating-point value, use a library function such as dectoint(), dectolong(), or dectodbl(). For more information about these decimal-conversion functions, see the Informix® ESQL/C Programmer's Manual.
The following table lists the functions that the library provides for the conversion and formatting of locale-specific data.
Table 1. conversion and formatting functions
Locale-specific data Conversion Formatting
Numeric ifx_gl_convert_number() ifx_gl_format_number()
Monetary ifx_gl_convert_money() ifx_gl_format_money()
Date ifx_gl_convert_date() ifx_gl_format_date()
Date/time ifx_gl_convert_datetime() ifx_gl_format_datetime()
The conversion and formatting functions in the preceding table accept a format string to indicate how to handle a locale-specific string. A format string is composed of white spaces, ordinary characters, and one or more formatting directives. A formatting directive consists of the following characters:
  • A percent symbol (%)
  • Optional format modifiers
  • A type-specifier character, which determines the type of conversion

For example, the ifx_gl_convert_number() function supports the following formatting directive: %0x

In the preceding formatting directive, 0 is a format modifier that indicates padding, and x is a type specifier that indicates the hexadecimal format of a number.