1 PACKAGE BODY FND_NUMBER as
2 /* $Header: AFNUMBRB.pls 115.15 2004/08/19 19:10:39 dmcmahon ship $ */
3
4 C_FORMAT constant varchar2(60) :=
5 'FM999999999999999999999.99999999999999999999';
6
7 --
8 -- Canonical functions
9 --
10
11 function canonical_to_number(
12 canonical varchar2)
13 return number is
14 decimal_char varchar2(1);
15 begin
16 if (canonical_mask <> C_FORMAT) then -- old behavior for 3757291
17 return to_number(canonical, canonical_mask);
18 end if;
19 decimal_char := substr(ltrim(to_char(.3,'0D0')),2,1);
20 return round(to_number(translate(canonical, '.', decimal_char)), 20);
21 end canonical_to_number;
22
23 function number_to_canonical(
24 numberval number)
25 return varchar2 is
26 decimal_char varchar2(1);
27 begin
28 if (canonical_mask <> C_FORMAT) then -- old behavior for 3757291
29 return rtrim(to_char(numberval, canonical_mask),'.');
30 end if;
31 decimal_char := substr(ltrim(to_char(.3,'0D0')),2,1);
32 return translate(to_char(round(numberval, 20)), decimal_char, '.');
33 end number_to_canonical;
34
35 -- use 'set serverout on;' to see the output from this test program
36
37 procedure test is
38 pi number := 3.1415;
39 my_char varchar2(20);
40 begin
41 /*
42 DBMS_OUTPUT.PUT_LINE('Decimal separator is '||fnd_number.decimal_char);
43 DBMS_OUTPUT.PUT_LINE('Group separator is '||fnd_number.group_separator);
44 DBMS_OUTPUT.PUT_LINE('Canonical mask is '||fnd_number.canonical_mask);
45
46 DBMS_OUTPUT.PUT_LINE('Canon number is '||fnd_number.number_to_canonical(pi));
47 DBMS_OUTPUT.PUT_LINE('and back is '||to_char(fnd_number.canonical_to_number('3.14')));
48 DBMS_OUTPUT.PUT_LINE('Canon integer is '||fnd_number.number_to_canonical(4));
49 select fnd_number.number_to_canonical(pi)
50 into my_char
51 from dual;
52
53 DBMS_OUTPUT.PUT_LINE('Canon number from SQL is '||my_char);
54
55 */
56 NULL;
57 end;
58
59
60 procedure initialize is
61
62 begin
63 canonical_mask := C_FORMAT;
64 decimal_char := substr(ltrim(to_char(.3,'0D0')),2,1);
65 group_separator := substr(ltrim(to_char(1032,'0G999')),2,1);
66 end ;
67
68
69 begin
70 canonical_mask := C_FORMAT;
71
72 -- OK, this is a bit kludgey, but I can't seem to find any way to access
73 -- the numeric characters directly.
74 decimal_char := substr(ltrim(to_char(.3,'0D0')),2,1);
75 group_separator := substr(ltrim(to_char(1032,'0G999')),2,1);
76 end FND_NUMBER;