On Mon, Dec 02, 2002 at 08:23:24PM +0100, Szima Gábor wrote:
> OK, but:
> 
> template1=# select round('2.001'::numeric);
>  round
> -------
>      2
> (1 row)
> 
> template1=# select round('2.001'::numeric,2);
>  round
> -------
>   2.00
> (1 row)
> 
> 
> The good idea (in 7.2):
> 
> template1=# select text('2.000'::numeric);
>  text
> ------
>  2
> (1 row)
> 
> template1=# select text('2.001'::numeric);
>  text
> -------
>  2.001
> (1 row)
> 
> 
> This feature is missing from 7.3..

Not sure I'd call it a feature -- ISTM that text(numeric) should show
all the precision you gave it, and not shave it down to the
least-precise number that is still equal.

Anyhoo, you can get what you want with some ugly-but-straightforward
trimming:

(in 7.3):

joel@joel=# select rtrim(rtrim('2.000'::numeric, '0'),'.');
 rtrim
-------
 2
(1 row)

joel@joel=# select rtrim(rtrim('2.001'::numeric, '0'),'.');
 rtrim
-------
 2.001
(1 row)


Easy enough to make this into a function trim_as_much(numeric) or
somesuch.

    
-- 

Joel BURTON  |  [EMAIL PROTECTED]  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to