Re: float formating with xx.00

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <map(at)inter-resa(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: float formating with xx.00
Date: 2003-07-04 03:09:21
Message-ID: D90A5A6C612A39408103E6ECDD77B8294CDE7F@voyager.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Thursday, July 03, 2003 6:33 PM
> To: Dann Corbit
> Cc: map(at)inter-resa(dot)com; pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] float formating with xx.00
>
>
> "Dann Corbit" <DCorbit(at)connx(dot)com> writes:
> >> Thanks... but will a numeric data type for money display the
> >> same output as
> >> the input? Ex.: I enter, 19.1 will it show 19.10 or 19.1 ?
>
> > If you are saying that you want the program to 'remember'
> exactly what
> > you typed in and use that, then you are stuck with strings.
>
> No, actually a column declared "numeric" (without any specific
> precision) will do that for him. This is a better choice
> than using a string IMHO.
>
> regression=# select '123.45'::numeric;
> numeric
> ---------
> 123.45
> (1 row)
>
> regression=# select '123.4'::numeric;
> numeric
> ---------
> 123.4
> (1 row)
>
> regression=# select '123.0'::numeric;
> numeric
> ---------
> 123.0
> (1 row)
>
> Not SQL-spec AFAIR, but Postgres will take it.

Can't say I am really positive what he was after. But I am not sure
that numeric without precision or scale qualfication will achieve his
goals either.

connxdatasync=# insert into test values (.99999999999999999999999999999)
connxdatasync-# ;
INSERT 29198 1
connxdatasync=# insert into test
values(99999999999999.99999999999999999999999999999999999999999999999999
999999999999999)
connxdatasync-# ;
INSERT 29199 1
connxdatasync=# create table test2 (foo numeric);
CREATE
connxdatasync=# insert into test2 values
(0.00000000000000000000000000000000000000);
INSERT 29210 1
connxdatasync=# insert into test2 values
(10.000000000000000000000000000000000000001);
INSERT 29211 1
connxdatasync=# insert into test2 values
(10.00000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000001);
INSERT 29212 1
connxdatasync=# insert into test2 values
(0.000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000001);
INSERT 29213 1
connxdatasync=# insert into test values (1.0/7.0);
INSERT 29214 1
connxdatasync=# insert into test2 values (1.0/7.0);
INSERT 29215 1
connxdatasync=# select foo::numeric from test;
?column?
-------------------
1
2.25
1.27
1.1
1
100000000000000
0.142857142857143
(7 rows)

connxdatasync=# select foo from test2;
foo
-----------
0.000000
10.000000
10.000000
0.000000
0.142857
(5 rows)

Don't know if this is the sort of result hoped for or not. Probably
not.

Now, this is 7.1.3. Don't know if 7.4 (or other flavors) behave
differently.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark 2003-07-04 03:16:52 Re: float formating with xx.00
Previous Message Tom Lane 2003-07-04 01:32:47 Re: float formating with xx.00