The ifx_int8todbl() function
The ifx_int8todbl() function converts an int8 type number into a C double type number.
Syntax
mint ifx_int8todbl(int8_val, dbl_val)
ifx_int8_t *int8_val;
double *dbl_val;
- int8_val
- A pointer to the int8 structure whose value ifx_int8todbl() converts to a double type value.
- dbl_val
- A pointer to a double value where ifx_int8todbl() places the result of the conversion.
Usage
The floating-point format of the host computer can result in loss of precision in the conversion of an int8 type number to a double type number.
Return codes
- 0
- The conversion was successful.
- <0
- The conversion failed.
Example
The file int8todbl.ec in
the demo directory contains the following sample
program.
/*
* ifx_int8todbl.ec *
The following program converts three strings to INT8
types and then to C double types and displays the
results.
*/
#include <stdio.h>
EXEC SQL include "int8.h";
char string1[] = "-12,555,444,333,786,456";
char string2[] = "480";
char string3[] = "5.2";
main()
{
mint x;
double d =0;
ifx_int8_t num1, num2, num3;
printf("\nIFX_INT8TODBL 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 double");
if (x= ifx_int8todbl(&num1, &d))
{
printf("\tError %d in converting INT8 to double\n", x);
exit(1);
}
else
{
printf("\nString 1= %s\n", string1);
printf("INT8 value is = %.10f\n", d);
}
printf("\nConverting second INT8 to double");
if (x= ifx_int8todbl(&num2, &d))
{
printf("\tError %d in converting INT8 to double\n", x);
exit(1);
}
else
{
printf("\nString2 = %s\n", string2);/*
printf("INT8 value is = %.10f\n",d);
}
printf("\nConverting third INT8 to double");
/* Note that the decimal places will be truncated. */
if (x= ifx_int8todbl(&num3, &d))
{
printf("\tError %d in converting INT8 to double\n", x);
exit(1);
}
else
{
printf("\nString3 = %s\n", string3);
printf("INT8 value is = %.10f\n",d);
}
printf("\nIFX_INT8TODBL Sample Program over.\n\n");
exit(0);
}
Output
IFX_INT8TODBL Sample ESQL Program running.
Converting INT8 to double
Executing: ifx_int8todbl(&num1,&d)
String 1= -12,555,444,333,786,456
The value of the first double is = -12555444333786456.0000000000
Converting second INT8 to double
Executing: ifx_int8todbl(&num2, &d)
String2 = 480
The value of the second double is = 480.0000000000
Converting third INT8 to double
Executing: ifx_int8todbl(&num3, &d)
String3 = 5.2
The value of the third double is = 5.0000000000
IFX_INT8TODBL Sample Program over.