示例
demo 目录中的文件 dectrunc.ec 包含下列样例程序。
/*
* dectrunc.ec *
The following program truncates a DECIMAL number six times and displays each result.
*/
#include
EXEC SQL include decimal;
char string[] = "-12345.038572";
char result[41];
main()
{
mint x;
mint i = 6; /* number of decimal places to start with */
dec_t num1;
printf("DECTRUNC Sample ESQL Program running.\n\n");
printf("String = %s\n", string);
while(i)
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 670 -
{
if (x = deccvasc(string, strlen(string), &num1))
{
printf("Error %d in converting string to DECIMAL\n", x);
break;
}
dectrunc(&num1, i);
if (x = dectoasc(&num1, result, sizeof(result), -1))
{
printf("Error %d in converting result to string\n", x);
break;
}
result[40] = '\0';
printf("Truncated to %d Fractional Digits: %s\n", i--, result);
}
printf("\nDECTRUNC Sample Program over.\n\n");
}
输出
DECTRUNC Sample ESQL Program running.
String = -12345.038572
Truncated to 6 Fractional Digits: -12345.038572
Truncated to 5 Fractional Digits: -12345.03857
Truncated to 4 Fractional Digits: -12345.0385
Truncated to 3 Fractional Digits: -12345.038
Truncated to 2 Fractional Digits: -12345.03
Truncated to 1 Fractional Digits: -12345.0
DECTRUNC Sample Program over.