Re: How to trim values?

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: jkakar(at)expressus(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to trim values?
Date: 2000-12-28 22:45:49
Message-ID: 200012282245.eBSMjpH02050@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

jkakar(at)expressus(dot)com wrote:
>Hi,
>
>I'm trying to figure out how to take a value like 3.68009074974387
>(that is calculated from values in my database) and have PostgreSQL
>hand me 3.68. Any suggestions would be appreciated.

cast it to numeric(x,2)

(where x is the total number of digits, and 2 is two decimal places).

template1=# select 3.68009074974387::numeric(3,2);
?column?
----------
3.68
(1 row)

or use round(value,2)

template1=# select round(3.68009074974387, 2);
round
-------
3.68
(1 row)

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"For God shall bring every work into judgment,
with every secret thing, whether it be good, or
whether it be evil." Ecclesiastes 12:14

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas SMETS 2000-12-29 03:40:23 Looking for comments
Previous Message jkakar 2000-12-28 22:00:46 How to trim values?