Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > math error or r...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9493 of 10966
Post > Topic >>

math error or rounding problem Money type

by justin@[EMAIL PROTECTED] (Justin) Jun 7, 2008 at 06:08 PM

This is a multi-part message in MIME format.
--------------070704020603080101010801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I believe i have found a math bug/rounding problem with Money type when 
its used with SUM()...  Postgresql 8.3.1

--------------- Background on the Problem--------------------

We have gl_trans table with 92,000 rows with one column containing the 
positive and negative entries.

In order to make this gl_trans table make more sense and to group the 
accounts in correct debits and credits along with type of accounts, A 
view was created that does grouping and sorting.   To further make 
things easier the view casted the results into the Money Type just to 
make the select statements that call the view shorter.

All looked great for several weeks till all of sudden the sumed values 
for all accounts goes out by 0.01. 

I needed to confirm this was a rounding problem and not  a GL entry that 
was bad.  ( if we had a bad entry this would scream we have a far bigger 
problem where the application allowed an GL entry to be committed that 
was out of balance)

To confirm that all entries made have equal and opposite entry  below 
select statement was created.  The  gltrans_sequence column is integer 
key that groups General Ledger entries together so all the sides of a 
specific entry can be found. 

select *
from
(select gltrans_sequence, sum(gltrans_amount) as Neg from gltrans  where 
gltrans_amount < 0 group by gltrans_sequence) as neg,
(select gltrans_sequence, sum(gltrans_amount) as pos from gltrans  where 
gltrans_amount > 0 group by gltrans_sequence) as pos
where neg.gltrans_sequence = pos.gltrans_sequence
and neg.neg <> pos.pos*-1

This returns no records as expected...

Now armed with that no entry was bad I suspected it had to be with the 
money data type.
So I added explicit castings

select *
from
(select gltrans_sequence, sum(gltrans_amount::text::money) as Neg from 
gltrans  where gltrans_amount < 0 group by gltrans_sequence) as neg,
(select gltrans_sequence, sum(gltrans_amount::text::money) as pos from 
gltrans  where gltrans_amount > 0 group by gltrans_sequence) as pos
where neg.gltrans_sequence = pos.gltrans_sequence
and neg.neg <> pos.pos*-1
----------------
select *
from
(select gltrans_sequence, sum(gltrans_amount::text::money) as Neg from 
gltrans  where gltrans_amount < 0 group by gltrans_sequence) as neg,
(select gltrans_sequence, sum(gltrans_amount::text::money) as pos from 
gltrans  where gltrans_amount > 0 group by gltrans_sequence) as pos
where neg.gltrans_sequence = pos.gltrans_sequence
and neg.neg::text::money <> pos.pos::text::money*-1
-------------
select *
from
(select gltrans_sequence, sum(gltrans_amount) as Neg from gltrans  where 
gltrans_amount < 0 group by gltrans_sequence) as neg,
(select gltrans_sequence, sum(gltrans_amount) as pos from gltrans  where 
gltrans_amount > 0 group by gltrans_sequence) as pos
where neg.gltrans_sequence = pos.gltrans_sequence
and neg.neg::text::money <> pos.pos::text::money*-1

-------------------
 Nothing  resulted in showing a entry that was out of balance. 





----------------------Identifying the problem ---------------------------

So i turned my attention to the view which casted numeric type to 
Money.  View is called trailbalance

------------The Bad Select Statement that creates the View --------------
SELECT p.period_id, p.period_start, p.period_end, a.accnt_id,
       a.accnt_number, a.accnt_descrip, p.period_yearperiod_id,
       a.accnt_type,
       SUM(CASE WHEN g.gltrans_date < p.period_start
                THEN g.gltrans_amount ELSE 0.0
           END)::text::money AS beginbalance,
       SUM(CASE WHEN g.gltrans_date <= p.period_end
                 AND g.gltrans_date >= p.period_start
                 AND g.gltrans_amount <= 0::numeric
                THEN g.gltrans_amount ELSE 0.0
           END)::text::money AS negative,
       SUM(CASE WHEN g.gltrans_date <= p.period_end
                 AND g.gltrans_date >= p.period_start
                 AND g.gltrans_amount >= 0::numeric
                THEN g.gltrans_amount ELSE 0.0
           END)::text::money AS positive,
       SUM(CASE WHEN g.gltrans_date <= p.period_end
                 AND g.gltrans_date >= p.period_start
                THEN g.gltrans_amount ELSE 0.0
           END)::text::money AS difference,
       SUM(CASE WHEN g.gltrans_date <= p.period_end
                THEN g.gltrans_amount ELSE 0.0
           END)::text::money AS endbalance
  FROM period p
 CROSS JOIN accnt a
  LEFT JOIN gltrans g ON (g.gltrans_accnt_id = a.accnt_id
                          AND g.gltrans_posted = true)
  where p.period_id = 58
 group by  p.period_id, p.period_start, p.period_end, a.accnt_id,
       a.accnt_number, a.accnt_descrip, p.period_yearperiod_id,
       a.accnt_type
 
 ORDER BY p.period_id, a.accnt_number;
---------------End Select --------------------


The query that calls this View 

------------------
Select
    sum( beginBalance ) as beginbalance,
    sum( negative ) as debit,
    sum( positive ) as credit,
    sum( difference ) as difference,
    sum( endbalance) as endbalance
 from trailbalance
---------------------

Result is 

-$0.01    -$11,250,546.74    $11,250,546.75  -$0.02   -$0.01

This be wrong.

Figuring it must be Money type dropped and recreated the view without 
the money casting.

------------The Fixed Select Statement that creates the View
--------------
SELECT p.period_id, p.period_start, p.period_end, a.accnt_id, 
a.accnt_number, a.accnt_descrip, p.period_yearperiod_id, a.accnt_type,
sum(
        CASE
            WHEN g.gltrans_date < p.period_start THEN g.gltrans_amount
            ELSE 0.0
        END) AS beginbalance, sum(
        CASE
            WHEN g.gltrans_date <= p.period_end AND g.gltrans_date >= 
p.period_start AND g.gltrans_amount <= 0::numeric THEN g.gltrans_amount
            ELSE 0.0
        END) AS negative, sum(
        CASE
            WHEN g.gltrans_date <= p.period_end AND g.gltrans_date >= 
p.period_start AND g.gltrans_amount >= 0::numeric THEN g.gltrans_amount
            ELSE 0.0
        END) AS positive, sum(
        CASE
            WHEN g.gltrans_date <= p.period_end AND g.gltrans_date >= 
p.period_start THEN g.gltrans_amount
            ELSE 0.0
        END) AS difference, sum(
        CASE
            WHEN g.gltrans_date <= p.period_end THEN g.gltrans_amount
            ELSE 0.0
        END) AS endbalance
   FROM period p
  CROSS JOIN accnt a
   LEFT JOIN gltrans g ON g.gltrans_accnt_id = a.accnt_id AND 
g.gltrans_posted = true
  GROUP BY p.period_id, a.accnt_number, p.period_start, p.period_end, 
a.accnt_id, a.accnt_descrip, p.period_yearperiod_id, a.accnt_type
  ORDER BY p.period_id, a.accnt_number;
---------------End Select --------------------


The above query results in this  which is what i would expect.

0.00000000    -11250546.74375232     11250546.74375232     
0.00000000     0.00000000


Now knowing for sure its in Money type casting i do this select statement
----------------------
Select
    '2',
    sum( beginBalance )::text::money as beginbalance,
    sum( negative )::text::money as debit,
    sum( positive )::text::money as credit,
    sum( difference )::text::money as difference,
    sum( endbalance)::text::money as endbalance
 from trailbalance
 union
 Select
    '1',
    sum( beginBalance::text::money) as beginbalance,
    sum( negative::text::money) as debit,
    sum( positive::text::money) as credit,
    sum( difference::text::money) as difference,
    sum( endbalance::text::money) as endbalance
 from trailbalance
-------------------------

The results I think very interesting
"1"  -$0.01   -$11,250,546.74     $11,250,546.75   -$0.02;   -$0.01
"2"  $0.00    -$11,250,546.74     $11,250,546.74    $0.00      $0.00

As you can see  casting to money before sum() is called are incorrect

Can anyone else confirm this odd behavior when casting to Money type.

Thank you for your time and patience reading this long post....




--------------070704020603080101010801
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
I believe i have found a math bug/rounding problem with Money type when
its used with SUM()...&nbsp; Postgresql 8.3.1<br>
<br>
--------------- Background on the Problem--------------------<br>
<br>
We have gl_trans table with 92,000 rows with one column containing the
positive and negative entries.<br>
<br>
In order to make this gl_trans table make more sense and to group the
accounts in correct debits and credits along with type of accounts, A
view was created that does grouping and sorting.&nbsp;&nbsp; To further
make
things easier the view casted the results into the Money Type just to
make the select statements that call the view shorter.<br>
<br>
All looked great for several weeks till all of sudden the sumed values
for all accounts goes out by 0.01.&nbsp; <br>
<br>
I needed to confirm this was a rounding problem and not&nbsp; a GL entry
that was bad.&nbsp; ( if we had a bad entry this would scream we have a
far
bigger problem where the application allowed an GL entry to be
committed that was out of balance)<br>
<br>
To confirm that all entries made have equal and opposite entry&nbsp; below
select statement was created.&nbsp; The&nbsp; gltrans_sequence column is
integer
key that groups General Ledger entries together so all the sides of a
specific entry can be found.&nbsp; <br>
<br>
select * <br>
from <br>
(select gltrans_sequence, sum(gltrans_amount) as Neg from gltrans&nbsp;
where gltrans_amount &lt; 0 group by gltrans_sequence) as neg,<br>
(select gltrans_sequence, sum(gltrans_amount) as pos from gltrans&nbsp;
where gltrans_amount &gt; 0 group by gltrans_sequence) as pos<br>
where neg.gltrans_sequence = pos.gltrans_sequence <br>
and neg.neg &lt;&gt; pos.pos*-1<br>
<br>
This returns no records as expected...<br>
<br>
Now armed with that no entry was bad I suspected it had to be with the
money data type.<br>
So I added explicit castings <br>
<font color="#3366ff"><br>
select * <br>
from <br>
(select gltrans_sequence, sum(gltrans_amount::text::money) as Neg from
gltrans&nbsp;
where gltrans_amount &lt; 0 group by gltrans_sequence) as neg,<br>
(select gltrans_sequence, sum(gltrans_amount::text::money) as pos from
gltrans&nbsp; where gltrans_amount &gt; 0 group by gltrans_sequence) as
pos<br>
where neg.gltrans_sequence = pos.gltrans_sequence <br>
and neg.neg &lt;&gt; pos.pos*-1</font><br>
----------------<br>
<font color="#3366ff">select * <br>
from <br>
(select gltrans_sequence, sum(gltrans_amount::text::money) as Neg from
gltrans&nbsp;
where gltrans_amount &lt; 0 group by gltrans_sequence) as neg,<br>
(select gltrans_sequence, sum(gltrans_amount::text::money) as pos from
gltrans&nbsp; where gltrans_amount &gt; 0 group by gltrans_sequence) as
pos<br>
where neg.gltrans_sequence = pos.gltrans_sequence <br>
and neg.neg::text::money &lt;&gt; pos.pos::text::money*-1</font><br>
-------------<br>
<font color="#3366ff">select * <br>
from <br>
(select gltrans_sequence, sum(gltrans_amount) as Neg from gltrans&nbsp;
where gltrans_amount &lt; 0 group by gltrans_sequence) as neg,<br>
(select gltrans_sequence, sum(gltrans_amount) as pos from
gltrans&nbsp; where gltrans_amount &gt; 0 group by gltrans_sequence) as
pos<br>
where neg.gltrans_sequence = pos.gltrans_sequence <br>
and neg.neg::text::money &lt;&gt; pos.pos::text::money*-1</font><br>
<br>
-------------------<br>
&nbsp;Nothing&nbsp; resulted in showing a entry that was out of
balance.&nbsp; <br>
<br>
<br>
<br>
<br>
<br>
----------------------Identifying the problem
---------------------------<br>
<br>
So i turned my attention to the view which casted numeric type to
Money.&nbsp; View is called trailbalance <br>
<br>
------------The Bad Select Statement that creates the View
--------------<br>
<font color="#3366ff">SELECT p.period_id, p.period_start, p.period_end,
a.accnt_id,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.accnt_number, a.accnt_descrip,
p.period_yearperiod_id,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.accnt_type,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(CASE WHEN g.gltrans_date &lt;
p.period_start<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THEN g.gltrans_amount ELSE 0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
END)::text::money AS beginbalance,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(CASE WHEN g.gltrans_date &lt;=
p.period_end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_date &gt;= p.period_start<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_amount &lt;= 0::numeric<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THEN g.gltrans_amount ELSE 0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
END)::text::money AS negative,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(CASE WHEN g.gltrans_date &lt;=
p.period_end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_date &gt;= p.period_start<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_amount &gt;= 0::numeric<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THEN g.gltrans_amount ELSE 0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
END)::text::money AS positive,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(CASE WHEN g.gltrans_date &lt;=
p.period_end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_date &gt;= p.period_start<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THEN g.gltrans_amount ELSE 0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
END)::text::money AS difference,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUM(CASE WHEN g.gltrans_date &lt;=
p.period_end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
THEN g.gltrans_amount ELSE 0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
END)::text::money AS endbalance<br>
&nbsp; FROM period p<br>
&nbsp;CROSS JOIN accnt a<br>
&nbsp; LEFT JOIN gltrans g ON (g.gltrans_accnt_id = a.accnt_id<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND g.gltrans_posted = true)<br>
&nbsp; where p.period_id = 58<br>
&nbsp;group by&nbsp; p.period_id, p.period_start, p.period_end,
a.accnt_id,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.accnt_number, a.accnt_descrip,
p.period_yearperiod_id,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.accnt_type<br>
&nbsp;<br>
&nbsp;ORDER BY p.period_id, a.accnt_number;</font><br>
---------------End Select --------------------<br>
<br>
<br>
The query that calls this View&nbsp; <br>
<br>
------------------<br>
<font color="#3366ff">Select <br>
&nbsp;&nbsp;&nbsp; sum( beginBalance ) as beginbalance, <br>
&nbsp;&nbsp;&nbsp; sum( negative ) as debit, <br>
&nbsp;&nbsp;&nbsp; sum( positive ) as credit, <br>
&nbsp;&nbsp;&nbsp; sum( difference ) as difference, <br>
&nbsp;&nbsp;&nbsp; sum( endbalance) as endbalance <br>
&nbsp;from trailbalance </font><br>
---------------------<br>
<br>
Result is&nbsp; <br>
<br>
<font color="#ff0000">-$0.01</font>&nbsp;&nbsp;&nbsp; -$11,250,546.74
&nbsp;&nbsp;
$11,250,546.75&nbsp;<font color="#ff0000"> -$0.02</font>&nbsp;&nbsp; <font
 color="#ff0000">-$0.01</font><br>
<br>
This be wrong. <br>
<br>
Figuring it must be Money type dropped and recreated the view without
the money casting. <br>
<br>
------------The Fixed Select Statement that creates the View
--------------<br>
<font color="#3366ff">SELECT p.period_id, p.period_start, p.period_end,
a.accnt_id,
a.accnt_number, a.accnt_descrip, p.period_yearperiod_id, a.accnt_type,
sum(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHEN
g.gltrans_date &lt; p.period_start THEN
g.gltrans_amount<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE
0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END) AS beginbalance, sum(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHEN
g.gltrans_date &lt;= p.period_end AND g.gltrans_date
&gt;= p.period_start AND g.gltrans_amount &lt;= 0::numeric THEN
g.gltrans_amount<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE
0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END) AS negative, sum(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHEN
g.gltrans_date &lt;= p.period_end AND g.gltrans_date
&gt;= p.period_start AND g.gltrans_amount &gt;= 0::numeric THEN
g.gltrans_amount<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE
0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END) AS positive, sum(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHEN
g.gltrans_date &lt;= p.period_end AND g.gltrans_date
&gt;= p.period_start THEN g.gltrans_amount<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE
0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END) AS difference, sum(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHEN
g.gltrans_date &lt;= p.period_end THEN g.gltrans_amount<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ELSE
0.0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END) AS endbalance<br>
&nbsp;&nbsp; FROM period p<br>
&nbsp; CROSS JOIN accnt a<br>
&nbsp;&nbsp; LEFT JOIN gltrans g ON g.gltrans_accnt_id = a.accnt_id AND
g.gltrans_posted = true<br>
&nbsp; GROUP BY p.period_id, a.accnt_number, p.period_start, p.period_end,
a.accnt_id, a.accnt_descrip, p.period_yearperiod_id, a.accnt_type<br>
&nbsp; ORDER BY p.period_id, a.accnt_number;</font><br>
---------------End Select --------------------<br>
<br>
<br>
The above query results in this&nbsp; which is what i would expect. <br>
<br>
0.00000000&nbsp;&nbsp;&nbsp; -11250546.74375232&nbsp;&nbsp;&nbsp;&nbsp;
11250546.74375232&nbsp;&nbsp;&nbsp;&nbsp;
0.00000000&nbsp;&nbsp;&nbsp;&nbsp; 0.00000000<br>
<br>
<br>
Now knowing for sure its in Money type casting i do this select
statement <br>
----------------------<br>
<font color="#3333ff">Select <br>
&nbsp;&nbsp;&nbsp; '2',<br>
&nbsp;&nbsp;&nbsp; sum( beginBalance )::text::money as beginbalance, <br>
&nbsp;&nbsp;&nbsp; sum( negative )::text::money as debit, <br>
&nbsp;&nbsp;&nbsp; sum( positive )::text::money as credit, <br>
&nbsp;&nbsp;&nbsp; sum( difference )::text::money as difference, <br>
&nbsp;&nbsp;&nbsp; sum( endbalance)::text::money as endbalance <br>
&nbsp;from trailbalance <br>
&nbsp;union <br>
&nbsp;Select <br>
&nbsp;&nbsp;&nbsp; '1',<br>
&nbsp;&nbsp;&nbsp; sum( beginBalance::text::money) as beginbalance, <br>
&nbsp;&nbsp;&nbsp; sum( negative::text::money) as debit, <br>
&nbsp;&nbsp;&nbsp; sum( positive::text::money) as credit, <br>
&nbsp;&nbsp;&nbsp; sum( difference::text::money) as difference, <br>
&nbsp;&nbsp;&nbsp; sum( endbalance::text::money) as endbalance <br>
&nbsp;from trailbalance </font><br>
-------------------------<br>
<br>
The results I think very interesting <br>
"1"&nbsp; <font color="#ff0000">-$0.01</font>&nbsp;&nbsp;
-$11,250,546.74&nbsp;&nbsp;&nbsp;&nbsp;
$11,250,546.75&nbsp;&nbsp; <font
color="#ff0000">-$0.02;</font>&nbsp;&nbsp; <font
 color="#ff0000">-$0.01</font><br>
"2"&nbsp; $0.00&nbsp;&nbsp;&nbsp; -$11,250,546.74&nbsp;&nbsp;&nbsp;&nbsp;
$11,250,546.74&nbsp;&nbsp;&nbsp; $0.00 &nbsp; &nbsp;&nbsp; $0.00<br>
<br>
As you can see&nbsp; casting to money before sum() is called are
incorrect<br>
<br>
Can anyone else confirm this odd behavior when casting to Money type.<br>
<br>
Thank you for your time and patience reading this long post....<br>
<br>
<br>
<br>
</body>
</html>

--------------070704020603080101010801--
 




 7 Posts in Topic:
math error or rounding problem Money type
justin@[EMAIL PROTECTED]   2008-06-07 18:08:40 
Re: math error or rounding problem Money type
tgl@[EMAIL PROTECTED] (T  2008-06-07 18:26:54 
Re: math error or rounding problem Money type
justin@[EMAIL PROTECTED]   2008-06-07 18:38:54 
Re: math error or rounding problem Money type
markir@[EMAIL PROTECTED]   2008-06-08 12:05:34 
Re: math error or rounding problem Money type
mmoncure@[EMAIL PROTECTED  2008-06-11 10:03:51 
Re: math error or rounding problem Money type
stark@[EMAIL PROTECTED]   2008-06-09 00:03:52 
Re: math error or rounding problem Money type
j.urbanski@[EMAIL PROTECT  2008-06-09 19:58:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 14:28:34 CST 2008.