decmul() 函数将两个 decimal 类型值相乘。
语法
mint decmul(n1, n2, product)
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 650 -
dec_t *n1;
dec_t *n2;
dec_t *product;
n1
指向第一个运算对象的 decimal 结构的指针。
n2
指向第二个运算对象的 decimal 结构的指针。
product
指向包含 n1 乘以 n2 的积的 decimal 结构的指针。
用法
product 可与 n1 或 n2 相同。
返回代码
0
操作成功。
-1200
操作导致溢出。
-1201
操作导致下溢。
示例
demo 目录中的 decmul.ec 文件包含下列示例程序。
/*
* decmul.ec *
This program multiplies two DECIMAL numbers and displays the result.
*/
#include
EXEC SQL include decimal;
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 651 -
char string1[] = "80.2";
char string2[] = "6.0";
char result[41];
main()
{
mint x;
dec_t num1, num2, mpx;
printf("DECMUL Sample ESQL Program running.\n\n");
if (x = deccvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to DECIMAL\n", x);
exit(1);
}
if (x = deccvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
if (x = decmul(&num1, &num2, &mpx))
{
printf("Error %d in converting multiply\n", x);
exit(1);
}
if (x = dectoasc(&mpx, result, sizeof(result), -1))
{
printf("Error %d in converting mpx to display string\n", x);
exit(1);
}
result[40] = '\0';
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 652 -
printf("\t%s * %s = %s\n", string1, string2, result);
printf("\nDECMUL Sample Program over.\n\n");
exit(0);
}
输出
DECMUL Sample ESQL Program running.
80.2 * 6.0 = 481.2
DECMUL Sample Program over.