dectolong() 函数将 decimal 类型数值转换为 int4 类型数值。
语法
mint dectolong(dec_val, lng_val)
dec_t *dec_val;
int4 *lng_val;
dec_val
指向 dectolong() 将其值转换为 int4 整数的 decimal 结构的指针。
lng_val
指向 dectolong() 放置转换的结果处的 int4 整数的指针。
返回代码
0
转换成功。
-1200
decimal 类型数值的大小大于 2,147,483,647。
示例
demo 目录中的文件 dectolong.ec 包含下列样例程序。
/*
* dectolong.ec *
The following program converts two DECIMAL numbers to longs and displays the return
value and the result for each conversion.
*/
#include
EXEC SQL include decimal;
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 667 -
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), #))
{
printf(" Error %d in converting string1 to DECIMAL\n", x);
exit(1);
}
if (x = dectolong(#, &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), #))
{
printf(" Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
if (x = dectolong(#, &n))
printf(" Error %d in converting DECIMAL2 to long\n", x);
else
printf(" Result = %ld\n", n);
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 668 -
printf("\nDECTOLONG Sample Program over.\n\n");
exit(0);
}
输出
DECTOLONG Sample ESQL Program running.
String 1 = 2147483647
Result = 2147483647
String 2 = 2147483648
Error -1200 in converting DECIMAL2 to long
DECTOLONG Sample Program over.