The ifx_int8cvdbl() function

The ifx_int8cvdbl() function converts a C double type number into an int8 type number.

Syntax

mint ifx_int8cvdbl(dbl_val, int8_val)
   double dbl_val;
   ifx_int8_t *int8_val;
dbl_val
The double value that ifx_int8cvdbl() converts to an int8 type value.
int8_val
A pointer to the int8 structure where ifx_int8cvdbl() places the result of the conversion.

Return codes

0
The conversion was successful.
<0
The conversion failed.

Example

The file int8cvdbl.ec in the demo directory contains the following sample program.
/*
   * int8cvdbl.ec *

    The following program converts two double type numbers 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;
    double d = 2147483647;

printf("IFX_INT8CVDBL Sample ESQL Program running.\n\n");

    printf("Number 1 (double) = 1234.5678901234\n");
    if (x = ifx_int8cvdbl((double)1234.5678901234, &num))
        {
        printf("Error %d in converting double1 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("  String Value = %s\n", result);

/* notice that the ifx_int8cvdbl function truncates digits to the
right of a decimal separator. */

    printf("Number 2 (double) = %.1f\n", d);
    if (x = ifx_int8cvdbl(d, &num))
        {
        printf("Error %d in converting double2 to INT8\n", x);
        exit(1);
        }
    if (x = ifx_int8toasc(&num, result, sizeof(result)))
        {
        printf("Error %d in converting second INT8 to string\n", x);
        exit(1);
        }
    result[40] = '\0';
    printf("  String Value = %s\n", result);

    printf("\nIFX_INT8CVDBL Sample Program over.\n\n");
    exit(0);
}

Output

IFX_INT8CVDBL Sample ESQL Program running.

Number 1 (double) = 1234.5678901234
  String Value = 1234
Number 2 (double) = 2147483647.0
  String Value = 2147483647

IFX_INT8CVDBL Sample Program over.