The deccvlong() function

The deccvlong() function converts a C long type value into a decimal type value.

Syntax

mint deccvlong(lng_val, dec_val)
   int4 lng_val;
   dec_t *dec_val;
lng_val
The int4 value that deccvlong() converts to a decimal type value.
dec_val
A pointer to a decimal structure where deccvlong() places the result of the conversion.

Return codes

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

Example

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

   The following program converts two longs to DECIMAL numbers and displays
   the results.
*/

#include <stdio.h>

EXEC SQL include decimal;

char result[41];
main()
{
    mint x;
    dec_t num; 

  int4 n;

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

   printf("Long Integer 1 = 129449233\n");
   if (x = deccvlong(129449233L, &num))
      {
      printf("Error %d in converting long to DECIMAL\n", x);
      exit(1);
      }
    if (x = dectoasc(&num, result, sizeof(result), -1))
      {
      printf("Error %d in converting DECIMAL to string\n", x);
      exit(1);
      }
    result[40] = '\0';
    printf("  String for Decimal Value = %s\n", result);

    n = 2147483646;                                     /* set n */
    printf("Long Integer 2 = %d\n", n);
    if (x = deccvlong(n, &num))
      {
      printf("Error %d in converting long to DECIMAL\n", x);
      exit(1);
      }
    if (x = dectoasc(&num, result, sizeof(result), -1))
      {
      printf("Error %d in converting DECIMAL to string\n", x);
      exit(1);
      }
    result[40] = '\0';
    printf("  String for Decimal Value = %s\n", result);

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

Output

DECCVLONG Sample ESQL Program running.

Long Integer 1 = 129449233
  String for Decimal Value =  129449233.0 
Long Integer 2 = 2147483646
  String for Decimal Value = 2147483646.0

DECCVLONG Sample Program over.