Convert numbers and strings

Before Informix® ESQL/C can convert a value from one data type to another, it must determine whether the conversion is meaningful.

The following table shows possible conversions between numeric data types and character data types. In this figure, N represents a value with a numeric data type (such as DECIMAL, FLOAT, or SMALLINT) and C represents a value with a character data type (such as CHAR or VARCHAR).

If conversion is not possible, either because it makes no sense or because the target variable is too small to accept the converted value, Informix® ESQL/C returns values that the Results column in the following table describes.
Table 1. Data conversion problems and results
Conversion Problem Results
C C Does not fit Informix® ESQL/C truncates the string, sets a warning (sqlca.sqlwarn.sqlwarn1 to W and SQLSTATE to 01004), and sets any indicator variable to the size of the original string.
N C None Informix® ESQL/C creates a string for the numeric value; it uses an exponential format for large or small numbers.
N C Does not fit Informix® ESQL/C fills the string with asterisks, sets a warning (sqlca.sqlwarn.sqlwarn1 to W and SQLSTATE to 01004), and sets any indicator variable to a positive integer.

When the fractional part of a number does not fit in a character variable, Informix® ESQL/C rounds the number. Asterisks are displayed only when the integer part does not fit.

C N None Informix® ESQL/C determines the numeric data type based on the format of the character value; if the character contains a decimal point, Informix® ESQL/C converts the value to a DECIMAL value.
C N Not a number The number is undefined; Informix® ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error.
C N Overflow The number is undefined; Informix® ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error.
N N Does not fit Informix® ESQL/C attempts to convert the number to the new data type.

For information about possible errors, see the Informix® Guide to SQL: Reference.

N N Overflow The number is undefined; Informix® ESQL/C sets sqlca.sqlcode and SQLSTATE to indicate a runtime error.

In Data conversion problems and results, the phrase Does not fit means that the size of the data from the source variable or column exceeds the size of the target column or variable.