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 General > Re: rounding pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 36 Topic 15511 of 17437
Post > Topic >>

Re: rounding problems

by justin@[EMAIL PROTECTED] (Justin) May 12, 2008 at 05:09 PM

As i'm playing around with rounding and the numeric field precision ran 
into a odd set of results i don't understand

here is the sql i wrote the first four inserts are calculations we run 
everyday and they make sense but if  division is used the results are 
not right or am i missing something

create table test_num (
    num1 numeric(20,1),
    num2 numeric(20,2),
    num3 numeric(20,3),
    num4 numeric(20,4),
    num5 numeric(20,5),
    num6 numeric(20,6),
    num7 numeric(20,7),
    num8 numeric(20,8),
    num9 numeric(20,9));

delete from test_num;

insert into test_num values ( (0.70 *1.05), (0.70 *1.05), (0.70 *1.05),
                  (0.70 *1.05), (0.70 *1.05), (0.70 *1.05),
                  (0.70 *1.05), (0.70 *1.05), (0.70 *1.05));

insert into test_num values ( (0.709 *1.05), (0.709 *1.05), (0.709 *1.05),
                  (0.709 *1.05), (0.709 *1.05), (0.709 *1.05),
                  (0.709 *1.05), (0.709 *1.05), (0.709 *1.05));
                 
insert into test_num values( (.5/.03), (.5/.3), (.5/3),
                 (.5/30), (.5/300), (.5/3000),
                 (.5/30000), (.5/30000), (.5/30000));


insert into test_num values( (.5/.03)*.9975, (.5/.3)*.9975, (.5/3)*.9975,
                 (.5/30)*.9975, (.5/300)*.9975, (.5/3000)*.9975,
                 (.5/30000)*.9975, (.5/30000)*.9975, (.5/30000)*.9975);
                 
insert into test_num values( (9*.1),
                 (9*.01),
                 (9*.001),
                 (9*.0001),
                 (9*.00001),
                 (9*.000001),
                 (9*.0000001),
                 (9*.00000001),
                 (9*.000000001));

insert into test_num values ( (9/10),
                  (9/100),
                  (9/1000),
                  (9/10000),
                  (9/100000),
                  (9/1000000),
                  (9/10000000),
                  (9/100000000),
                  (9/1000000000));
                 
insert into test_num values( (1*.1),
                 (1*.01),
                 (1*.001),
                 (1*.0001),
                 (1*.00001),
                 (1*.000001),
                 (1*.0000001),
                 (1*.00000001),
                 (1*.000000001));
                
insert into test_num values ( (1/10),
                  (1/100),
                  (1/1000),
                  (1/10000),
                  (1/100000),
                  (1/1000000),
                  (1/10000000),
                  (1/100000000),
                  (1/1000000000));

select * from test_num ;
   
   

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 36 Posts in Topic:
rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 13:48:16 
Re: rounding problems
lyeoh@[EMAIL PROTECTED]   2008-05-13 02:07:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:54:47 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 15:08:11 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 04:29:06 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:02:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:09:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:23:15 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:50:16 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 18:37:02 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 19:04:13 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-13 02:20:18 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 22:51:42 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 11:42:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 00:16:06 
Re: rounding problems
xof@[EMAIL PROTECTED] (C  2008-05-12 14:53:21 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:26:46 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 14:18:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:49:48 
Re: rounding problems
tometzky@[EMAIL PROTECTED  2008-05-13 08:40:41 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 11:30:48 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:29:07 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 14:36:18 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 15:38:17 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 11:47:52 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 17:26:30 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 20:27:19 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:02:32 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:08:54 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:24:58 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:55:49 
Re: rounding problems
glene77is <glen.e77is@  2008-05-20 03:19:20 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-20 10:28:28 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 15:56:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:01:11 
Re: rounding problems
doug@[EMAIL PROTECTED] (  2008-05-13 12:12:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Nov 22 12:11:01 CST 2008.