The ifx_int8toflt() function
The ifx_int8toflt() function converts an int8 type number into a C float type number.
Syntax
mint ifx_int8toflt(int8_val, flt_val)
ifx_int8_t *int8_val;
float *flt_val;
- int8_val
- A pointer to an int8 structure whose value ifx_int8toflt()converts to a float type value.
- flt_val
- A pointer to a float value where ifx_int8toflt() places the result of the conversion.
Usage
The ifx_int8toflt() library function converts an int8 value to a C float. The size of a C float depends upon the hardware and operating system of the computer you are using.
Return codes
- 0
- The conversion was successful.
- <0
- The conversion failed.
Example
The file int8toflt.ec in
the demo directory contains the following sample
program.
/*
* ifx_int8toflt.ec *
The following program converts three strings to
INT8 values and then to float values and
displays the results.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char string1[] = "-12,555.765";
char string2[] = "480.76";
char string3[] = "5.2";
main()
{
mint x;
float f =0.0;
ifx_int8_t num1, num2, num3;
printf("\nIFX_INT8TOFLT Sample ESQL Program running.\n\n");
if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}
printf("\nConverting INT8 to float\n");
if (x= ifx_int8toflt(&num1, &f))
{
printf("\tError %d in converting INT8 to float\n", x);
exit(1);
}
else
{
printf("String 1= %s\n", string1);
printf("INT8 value is = %f\n", f);
}
printf("\nConverting second INT8 to float\n");
if (x= ifx_int8toflt(&num2, &f))
{
printf("\tError %d in converting INT8 to float\n", x);
exit(1);
}
else
{
printf("String2 = %s\n", string2);
printf("INT8 value is = %f\n", f);
}
printf("\nConverting third INT8 to integer\n");
/* Note that the decimal places will be truncated */
if (x= ifx_int8toflt(&num3, &f))
{
printf("\tError %d in converting INT8 to float\n", x);
exit(1);
}
else
{
printf("String3 = %s\n", string3);
printf("INT8 value is = %f\n",f);
}
printf("\nIFX_INT8TOFLT Sample Program over.\n\n");
exit(0);
}
Output
IFX_INT8TOFLT Sample ESQL Program running.
Converting INT8 to float
Executing: ifx_int8toflt(&num1,&f)
String 1= -12,555.765
The value of the first float is = -12555.000000
Converting second INT8 to float
Executing: ifx_int8toflt(&num2, &f)
String2 = 480.76
The value of the second float is = 480.000000
Converting third INT8 to integer
Executing: ifx_int8toflt(&num3, &f)
String3 = 5.2
The value of the third float is = 5.000000
IFX_INT8TOFLT Sample Program over.