ifx_int8cvflt() 函数将 C float 类型数值转换为 int8 类型数值。
语法
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 731 -
mint ifx_int8cvflt(flt_val, int8_val)
double flt_val;
ifx_int8_t *int8_val;
flt_val
ifx_int8cvflt() 要将其转换为 int8 类型值的 float 值。
int8_val
指向 ifx_int8cvflt() 放置转换的结果处的 int8 结构的指针。
返回代码
0
转换成功。
<0
转换失败。
示例
demo 目录中的文件 int8cvflt.ec 包含下列样例程序。
/*
* ifx_int8cvflt.ec *
The following program converts two floats to INT8 types and displays the results.
*/
#include
EXEC SQL include "int8.h";
char result[41];
main()
{
mint x;
ifx_int8_t num;
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 732 -
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, #))
{
printf("Error %d in converting float1 to INT8\n", x);
exit(1);
}
/* Convert int8 to ascii to display value. */
if (x = ifx_int8soasc(#, 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, #))
{
printf("Error %d in converting float2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8soasc(#, result, sizeof(result)))
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 733 -
{
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);
}
输出
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.