INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 5: Working with Numeric Data Types
Home Contents Index Master Index New Book

The Floating-Point Data Types

The database server supports the following data types for floating-point values.
SQL Floating-Point
Data Type
ESQL/C or C Language Type Range of Values

SMALLFLOAT, REAL

float

Single-precision values with up to 8 significant digits

FLOAT,
DOUBLE PRECISION

double

Double-precision values with up to 16 significant digits

DECIMAL(p)

decimal

Absolute value range between 10-130 and 10124

Declaring float Host Variables

When you use the C float data type (for SMALLFLOAT values), be aware that most C compilers pass float to a function as the double data type. If you declare the function argument as a float, you might receive an incorrect result. For example, in the following excerpt, :hostvar might produce an incorrect value in tab1, depending on how your C compiler handles the float data type when your program passes it as an argument.

For more information on the DECIMAL data type, see Chapter 4, "Working with the DECIMAL Data Type."

Implicit Data Conversion

When an ESQL/C program fetches a floating-point column value (data type of DECIMAL(n), FLOAT, or SMALLFLOAT) into a character host variable (char, fixchar, varchar, or string), it includes only the number of decimal digits that can fit into the character buffer. If the host variable is too small for the full precision of the floating-point number, ESQL/C rounds the number to the precision that the host variable can hold.

In the following code fragment, an ESQL/C program retrieves the value 1234.8763512 from a FLOAT column that is called principal into the prncpl_strng character host variable:

Because the prncpl_strng host variable is a buffer of 15 characters, ESQL/C is able to put all decimal digits into the host variable and this code fragment produces the following output:

However, if the preceding code fragment declares the prncpl_strng host variable as a buffer of 10 characters, ESQL/C rounds the FLOAT value to fit into prncpl_strng and the code fragment produces the following output:

ESQL/C assumes a precision of 16 decimal digits for DECIMAL(n), FLOAT, or SMALLFLOAT values. (For DECIMAL(n,m), ESQL/C assumes m decimal digits.)




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.