The ifx_int8cvflt() function
The ifx_int8cvflt() function converts a C float type number into an int8 type number.
Syntax
mint ifx_int8cvflt(flt_val, int8_val)
double flt_val;
ifx_int8_t *int8_val;
- flt_val
- The float value that ifx_int8cvflt() converts to an int8 type value.
- int8_val
- A pointer to the int8 structure where ifx_int8cvflt() places the result of the conversion.
Return codes
- 0
- The conversion was successful.
- <0
- The conversion failed.
Example
The file int8cvflt.ec in
the demo directory contains the following sample
program.
/*
* ifx_int8cvflt.ec *
The following program converts two floats to INT8 types and displays
the results.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char result[41];
main()
{
mint x;
ifx_int8_t num;
printf("IFX_INT8CVFLT Sample ESQL Program running.\n\n");
printf("Float 1 = 12944.321\n");
/* Note that in the following conversion, the digits to the
right of the decimal are ignored. */
if (x = ifx_int8cvflt(12944.321, &num))
{
printf("Error %d in converting float1 to INT8\n", x);
exit(1);
}
/* Convert int8 to ascii to display value. */
if (x = ifx_int8toasc(&num, result, sizeof(result)))
{
printf("Error %d in converting INT8 to string\n", x);
exit(1);
}
result[40] = '\0';
printf(" The INT8 type value is = %s\n", result);
printf("Float 2 = -33.43\n");
/* Note that in the following conversion, the digits to the
right of the decimal are ignored. */
if (x = ifx_int8cvflt(-33.43, &num))
{
printf("Error %d in converting float2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8toasc(&num, result, sizeof(result)))
{
printf("Error %d in converting INT8 to string\n", x);
exit(1);
}
result[40] = '\0';
printf(" The second INT8 type value is = %s\n", result);
printf("\nIFX_INT8CVFLT Sample Program over.\n\n");
exit(0);
}
Output
IFX_INT8CVFLT Sample ESQL Program running.
Float 1 = 12944.321
The INT8 type value is = 12944
Float 2 = -33.43
The second INT8 type value is = -33
IFX_INT8CVFLT Sample Program over.