The deccvint() function

The deccvint() function converts a C int type number into a decimal type number.

Syntax

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

Return codes

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

Example

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

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

#include <stdio.h>

EXEC SQL include decimal;

char result[41];

main()
{
    mint x;
    dec_t num;

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

    printf("Integer 1 = 129449233\n");
    if (x = deccvint(129449233, &num))
      {
      printf("Error %d in converting int1 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("Integer 2 = 33\n");
   if (x = deccvint(33, &num))
      {
      printf("Error %d in converting int2 to DECIMAL\n", x);
      exit(1);
      }
   result[40] = '\0';
   printf("  String for Decimal Value = %s\n", result);

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

Output

DECCVINT Sample ESQL Program running.

Integer 1 = 129449233
  String for Decimal Value = 129449233.0
Integer 2 = 33
  String for Decimal Value = 33.0 

DECCVINT Sample Program over.