Thread: How to trim values?

How to trim values?

From
jkakar@expressus.com
Date:
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.

Thanks,
Jamu.

-- 
Jamu Kakar (Developer)            Expressus Design Studio, Inc.
jkakar@expressus.com            708-1641 Lonsdale Avenue
V: (604) 903-6999            North Vancouver, BC, V7M 2J5


Simultaneous Connection Problem

From
Webb Sprague
Date:
I have a table that is sequence_number (my PK), session_start_time, and
session_stop_stime.  I would like to query it to determine the max number
of simultaneous sessions.  Has anyone conquered a problem like this?  It
seems like it should be in a book somewhere, but I haven't found it yet.

Thanks,
-- 
Webb Sprague
Programmer
O1 Communications



Re: How to trim values?

From
"Oliver Elphick"
Date:
jkakar@expressus.com wrote: >Hi, > >I'm trying to figure out how to take a value like 3.68009074974387 >(that is
calculatedfrom 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.Elphick@lfix.co.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,
whetherit be good, or       whether it be evil."               Ecclesiastes 12:14 
 




Re: How to trim values?

From
Karel Zak
Date:
On Thu, 28 Dec 2000, Oliver Elphick wrote:

> jkakar@expressus.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)

or

test=# select to_char(3.68009074974387, '99.99');to_char
---------  3.68
(1 row)
        Karel