Skip site navigation (1) Skip section navigation (2)

Re: Numeric Data Type Rounding Up

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Numeric Data Type Rounding Up
Date: 2012-03-07 17:19:08
Message-ID: 4F57988C.1040509@pinpointresearch.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 03/07/2012 08:50 AM, Carlos Mennens wrote:
> I have a table...
>                                  Table "public.weight"
>   Column |         Type          |                      Modifiers
> --------+-----------------------+-----------------------------------------------------
> ...
>   lbs    | numeric(5,0)          | not null
> ...
> Now when I enter a value in the 'lbs' field / column of '172.80', it
> rounds the value up to '173.00'.
You specified a precision of 0. Try 2 (if you really want to track to 
the 100th of a pound) or 1 for 1/10 pound. numeric(5,2) will be good up 
to 999.99 pounds.

steve=# select 123.45::numeric(5,0);
  numeric
---------
      123

steve=# select 123.45::numeric(5,1);
  numeric
---------
    123.5

steve=# select 123.45::numeric(5,2);
  numeric
---------
   123.45

Cheers,
Steve


In response to

pgsql-novice by date

Next:From: Jude LucienDate: 2012-03-08 22:24:42
Subject: How To Store Large Text Strings
Previous:From: Carlos MennensDate: 2012-03-07 17:19:00
Subject: Re: Numeric Data Type Rounding Up

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group