返回首页

gbase数据、南大通用产品文档:GBase8sifx_int8todec() 函数

更新日期:2024年09月11日

ifx_int8todec() 函数将 int8 类型数值转换为 decimal 类型数值。
语法

mint ifx_int8todec(int8_val, dec_val)
ifx_int8_t *int8_val;
dec_t *dec_val;
int8_val
指向 ifx_int8todec() 将其值转换为 decimal 类型值的 int8 结构的指针。
dec_val
指向 ifx_int8todec() 在其中放置转换的结果的 decimal 结构的指针。

返回代码
0
转换成功。
<0
转换不成功。

示例
demo 目录中的文件 int8todec.ec 包含下列样例程序。
/*
* ifx_int8todec.ec *

The following program converts three strings to INT8 types and

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 755 -

converts the INT8 type values to decimal type values.
Then the values are displayed.

*/

#include

EXEC SQL include "int8.h";
#define END sizeof(result)

char string1[] = "-12,555,444,333,786,456";
char string2[] = "480";
char string3[] = "5.2";
char result [40];

main()
{
mint x;
dec_t d;
ifx_int8_t num1, num2, num3;
printf("IFX_INT8tODEC Sample ESQL Program running.\n\n");

if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 756 -

{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}

printf("\n***Converting INT8 to decimal\n");
printf("\nString 1= %s\n", string1);
printf(" \nExecuting: ifx_int8todec(&num1,&d)");
if (x= ifx_int8todec(&num1, &d))
{
printf("\tError %d in converting INT8 to decimal\n", x);
exit(1);
}
else
{
printf("\nConverting Decimal to ASCII for display\n");
printf("Executing: dectoasc(&d, result, END, -1)\n");
if (x = dectoasc(&d, result, END, -1))
printf("\tError %d in converting DECIMAL1 to string\n", x);
else
{
result[END - 1] = '\0'; /* null terminate */
printf("Result = %s\n", result);
}
}
printf("\n***Converting second INT8 to decimal\n");
printf("\nString2 = %s\n", string2);
printf(" \nExecuting: ifx_int8todec(&num2, &d)");
if (x= ifx_int8todec(&num2, &d))
{
printf("\tError %d in converting INT8 to decimal\n", x);
exit(1);
}

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 757 -

else
{
printf("\nConverting Decimal to ASCII for display\n");
printf("Executing: dectoasc(&d, result, END, -1)\n");
if (x = dectoasc(&d, result, END, -1))
printf("\tError %d in converting DECIMAL2 to string\n", x);
else
{
result[END - 1] = '\0'; /* null terminate */
printf("Result = %s\n", result);
}
}
printf("\n***Converting third INT8 to decimal\n");
printf("\nString3 = %s\n", string3);
printf(" \nExecuting: ifx_int8todec(&num3, &d)");
if (x= ifx_int8todec(&num3, &d))
{
printf("\tError %d in converting INT8 to decimal\n", x);
exit(1);
}
else
{
printf("\nConverting Decimal to ASCII for display\n");
printf("Executing: dectoasc(&d, result, END, -1)\n");

/* note that the decimal is truncated */

if (x = dectoasc(&d, result, END, -1))
printf("\tError %d in converting DECIMAL3 to string\n", x);
else
{
result[END - 1] = '\0'; /* null terminate */
printf("Result = %s\n", result);

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 758 -

}
}
printf("\nIFX_INT8tODEC Sample Program over.\n\n");
exit(0);
}
输出
IFX_INT8tODEC Sample ESQL Program running.


***Converting INT8 to decimal

String 1= -12,555,444,333,786,456

Executing: ifx_int8todec(&num1,&d)
Converting Decimal to ASCII for display
Executing: dectoasc(&d, result, END, -1)
Result = -12555444333786456.0

***Converting second INT8 to decimal

String2 = 480

Executing: ifx_int8todec(&num2, &d)
Converting Decimal to ASCII for display
Executing: dectoasc(&d, result, END, -1)
Result = 480.0

***Converting third INT8 to decimal

String3 = 5.2

Executing: ifx_int8todec(&num3, &d)
Converting Decimal to ASCII for display

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 759 -

Executing: dectoasc(&d, result, END, -1)
Result = 5.0
IFX_INT8tODEC Sample Program over.

PG_CONVERSION 系统表描述编码转换信息。
名称
类型
引用
描述
oid
oid
-
行标识符(隐藏属性,必须明确
选择)。
conname
name
-
转换名称(在一个名称空间里是
唯一的)。
connamespace
oid
PG_NAMESPACE.o
id
包含这个转换的名称空间的OI
D。
conowner
oid
PG_AUTHID.oid
编码转换的属主。
conforencoding
integer
-
源编码ID。
contoencoding
integer
-
目的编码ID。
conproc
regproc
PG_PROC.proname
转换过程。
condefault
boolean
-
如果这是缺省转换则为真。

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
779

函数说明
返回数值X 截取到D 位小数后的数字。D 为可选参数,默认值为0。
如果D 为0,结果将不包含小数点和小数部分。
如果D 为负数,表示截去(归零)X 值小数点左边第D 位开始后面所有低位的
值。
示例
示例1:X 为“1.223”,小数点后保留一位。
gbase> SELECT TRUNCATE(1.223,1) FROM dual;
+-------------------+
| TRUNCATE(1.223,1) |
+-------------------+
|