The decimal.h header file also includes the following macros that might be useful in a DataBlade API module.

Decimal Macro Description
DECLEN(p, s) Calculates the minimum number of bytes required to hold the DECIMAL(p,s) value
DECPREC(size) Calculates a default precision given the number of bytes (size) used to store the number
PRECTOT(dec) Returns the total precision of the dec value
PRECDEC(dec) Returns the scale of the dec value
PRECMAKE(p, s) Creates a precision value from the specified total precision (p) and scale (s)

Tip: For a complete list of decimal macros, consult the decimal.h header file that is installed with your database server. This header file resides in the incl/public subdirectory of the INFORMIXDIR directory. ESQL/C DECIMAL-Type Functions

Because the binary representation of DECIMAL (mi_decimal) and MONEY (mi_money) values is an Informix-proprietary format, you cannot use standard system functions to perform decimal operations on mi_decimal and mi_money values. Instead, the DataBlade API provides support for the following ESQL/C functions on the DECIMAL and MONEY data types.

Type of DECIMAL Function For More Information
Conversion functions ESQL/C Functions for Decimal Conversion
Arithmetic-operation functions Performing Operations on Decimal Data

Any other operations, modifications, or analyses can produce unpredictable results.

Transferring Fixed-Point Data

To transfer fixed-point data between different computer architectures, the DataBlade API provides the following functions that handle type alignment and byte order.

DataBlade API
Function
Description
mi_get_decimal() Copies an aligned mi_decimal value, converting any difference in alignment or byte order on the client computer to that of the server computer.
mi_get_money() Copies an aligned mi_money value, converting any difference in alignment or byte order on the client computer to that of the server computer.
mi_put_decimal() Copies an aligned mi_decimal value, converting any difference in alignment or byte order on the server computer to that of the client computer.
mi_put_money() Copies an aligned mi_money value, converting any difference in alignment or byte order on the server computer to that of the client computer.

The mi_get_decimal(), mi_get_money(), mi_put_decimal(), and mi_put_money() functions are useful in the send and receive support function of an opaque data type that contains mi_decimal or mi_money values. They ensure that fixed-point (DECIMAL or MONEY) values remain aligned when transferred to and from client applications. For more information, see Converting Opaque-Type Data With Machine-Specific Data Types.

Converting Decimal Data

Both the DataBlade API library and the ESQL/C library provide functions that convert the binary representation for DECIMAL (mi_decimal) or MONEY (mi_money) values.

DataBlade API Functions for Decimal Conversion

The DataBlade API library provides the following functions that convert between a text (string) representation of a decimal or monetary value and its binary (internal) equivalent.

DataBlade API Function Converts From Converts To
mi_decimal_to_string() DECIMAL (mi_decimal) Decimal string
mi_money_to_string() MONEY (mi_money) Interval string
mi_string_to_decimal() Decimal string DECIMAL (mi_decimal)
mi_string_to_money() Monetary string MONEY (mi_money)

The mi_decimal_to_string(), mi_money_to_string(), mi_string_to_decimal(), and mi_string_to_money() functions are useful in the input and output support function of an opaque data type that contains mi_decimal or mi_money values. They allow you to convert fixed-point (DECIMAL or MONEY) values between their external format (text) and their internal format (dec_t) when transferred to and from client applications. For more information, see Converting Opaque-Type Data Between Text and Binary Representations.

The mi_decimal_to_string(), mi_money_to_string(), mi_string_to_decimal(), and mi_string_to_money() functions use the current processing locale to handle locale-specific formats in the decimal or monetary string. For more information, see Informix Guide to GLS Functionality.

ESQL/C Functions for Decimal Conversion

The ESQL/C function library provides the following functions to convert a DECIMAL (or MONEY) value to and from some C-language data types.

Function Name Description
deccvasc() Converts a C char type to an mi_decimal type value
deccvdbl() Converts a C double (mi_double_precision) type to an mi_decimal type value
deccvint() Converts a C 2-byte integer value to an mi_decimal type value
deccvlong() Converts a C 4-byte integer value to an mi_decimal type value
dececvt() and decfcvt() Converts an mi_decimal type value to text
dectoasc() Converts an mi_decimal type value to text
dectodbl() Converts an mi_decimal type value to a C double (mi_double_precision) type value
dectoint() Converts an mi_decimal type value to a C 2-byte integer value
dectolong() Converts an mi_decimal type value to a C 4-byte integer value

Tip: The ESQL/C library also provides functions to convert some numeric data types to formatted strings. For more information, see Formatting Numeric Strings.

Performing Operations on Decimal Data

The ESQL/C function library provides the following functions to perform arithmetic operations on DECIMAL (mi_decimal) and MONEY (mi_money) values.

Function Name Description
decadd() Adds two mi_decimal numbers
deccmp() Compares two mi_decimal numbers
deccopy() Copies a mi_decimal number
decdiv() Divides two mi_decimal numbers
decmul() Multiplies two mi_decimal numbers
decround() Rounds an mi_decimal number
decsub() Subtracts two mi_decimal numbers
dectrunc() Truncates an mi_decimal number

Any other operations, modifications, or analyses can produce unpredictable results.

Obtaining Fixed-Point Type Information

The DataBlade API provides the following functions to obtain the scale and precision of a fixed-point (DECIMAL and MONEY) data type.

Source DataBlade API Functions
For a data type mi_type_precision(), mi_type_scale()
For a UDR argument mi_fp_argprec(), mi_fp_setargprec() mi_fp_argscale(), mi_fp_setargscale()
For a UDR return value mi_fp_retprec(), mi_fp_setretprec() mi_fp_retscale(), mi_fp_setretscale()
For a column in a row (or field in a row type) mi_column_precision(), mi_column_scale()
For an input parameter in a prepared statement mi_parameter_precision(), mi_parameter_scale()


Informix DataBlade API Programmer's Manual, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved