The dectolong() function
The dectolong() function converts a decimal type number into an int4 type number.
Syntax
mint dectolong(dec_val, lng_val)
dec_t *dec_val;
int4 *lng_val;
- dec_val
- A pointer to a decimal structure whose value dectolong() converts to an int4 integer.
- lng_val
- A pointer to an int4 integer where dectolong() places the result of the conversion.
Return codes
- 0
- The conversion was successful.
- -1200
- The magnitude of the decimal type number is greater than 2,147,483,647.
Example
The file dectolong.ec in
the demo directory contains the following sample
program.
/*
* dectolong.ec *
The following program converts two DECIMAL numbers to longs and displays
the return value and the result for each conversion.
*/
#include <stdio.h>
EXEC SQL include decimal;
char string1[] = "2147483647";
char string2[] = "2147483648";
main()
{
int x;
long n = 0;
dec_t num;
printf("DECTOLONG Sample ESQL Program running.\n\n");
printf("String 1 = %s\n", string1);
if (x = deccvasc(string1, strlen(string1), &num))
{
printf(" Error %d in converting string1 to DECIMAL\n", x);
exit(1);
}
if (x = dectolong(&num, &n))
printf(" Error %d in converting DECIMAL1 to long\n", x);
else
printf(" Result = %ld\n", n);
printf("\nString 2 = %s\n", string2);
if (x = deccvasc(string2, strlen(string2), &num))
{
printf(" Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
if (x = dectolong(&num, &n))
printf(" Error %d in converting DECIMAL2 to long\n", x);
else
printf(" Result = %ld\n", n);
printf("\nDECTOLONG Sample Program over.\n\n");
exit(0);
}
Output
DECTOLONG Sample ESQL Program running.
String 1 = 2147483647
Result = 2147483647
String 2 = 2147483648
Error -1200 in converting DECIMAL2 to long
DECTOLONG Sample Program over.