2 #include <pgtypes_numeric.h>
9 Numeric *value1, *value2, *res;
10 exec sql begin declare section;
11 numeric(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
12 exec sql end declare section;
16 if ((dbgs = fopen("log", "w")) != NULL)
18 exec sql whenever sqlerror do sqlprint();
20 exec sql connect to mm;
21 exec sql create table test (text char(5), num numeric(14,7));
23 value1 = PGTYPESnumeric_new();
24 PGTYPESnumeric_from_int(1407, value1);
25 text = PGTYPESnumeric_to_asc(value1, 0);
26 printf("long = %s\n", text);
28 value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
29 value2 = PGTYPESnumeric_from_asc("10.0", NULL);
30 res = PGTYPESnumeric_new();
31 PGTYPESnumeric_add(value1, value2, res);
32 text = PGTYPESnumeric_to_asc(res, 0);
33 printf("add = %s\n", text);
35 PGTYPESnumeric_sub(res, value2, res);
36 text = PGTYPESnumeric_to_asc(res, 0);
37 printf("sub = %s\n", text);
39 PGTYPESnumeric_copy(res, &des);
40 exec sql insert into test (text, num) values ('test', :des);
42 value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
43 PGTYPESnumeric_mul(value1, value2, res);
45 exec sql select num into :des from test where text = 'test';
47 PGTYPESnumeric_mul(res, &des, res);
48 text = PGTYPESnumeric_to_asc(res, 0);
49 printf("mul = %s\n", text);
51 value2 = PGTYPESnumeric_from_asc("10000", NULL);
52 PGTYPESnumeric_div(res, value2, res);
53 text = PGTYPESnumeric_to_asc(res, 0);
54 PGTYPESnumeric_to_double(res, &d);
55 printf("div = %s %e\n", text, d);