Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Location
    Orlando, FL
    Posts
    311
    Provided Answers: 1

    Question Unanswered: PostgreSQL Rounding Up NUMERIC Values

    I have a table called weight and this table is tracking weight for a few people in a fitness program that just started. I created the table as described below:

    Code:
    fitness=# \d weight
                                    Table "public.weight"
     Column |         Type          |                      Modifiers                      
    --------+-----------------------+-----------------------------------------------------
     id     | integer               | not null default nextval('weight_id_seq'::regclass)
     lbs    | numeric(5,0)          | not null
     date   | date                  | not null
     dow    | character varying(9)  | not null
     name   | character varying(50) | not null
    Indexes:
        "weight_pkey" PRIMARY KEY, btree (id)
    Now when I enter a value in the 'lbs' field / column of '172.80', it rounds the value up to '173.00'. I looked on the documentation and found a numeric data type called 'real'. I tried changing the data type from 'NUMERIC' to 'REAL' but it didn't work. I honestly don't know if that is even the correct numeric data type I want / need to show exact values on something like tracking weight figures. Can someone tell me if I'm way off here?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Of course it's rounded, because you told PostgreSQL to do so. The 0 in numeric(5,0) mean "no fractional digits". You probably want numeric(5,2) which means a total of 5 digits with two fractional digits.

  3. #3
    Join Date
    Oct 2010
    Location
    Orlando, FL
    Posts
    311
    Provided Answers: 1
    Sorry I realized that shorty after I posted. Sorry I missed that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •