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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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