From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chris Gernon <kabigon@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values
Date: Tue, 20 Sep 2011 13:49:28 -0400
Message-ID: <11125.1316540968@sss.pgh.pa.us> (raw)
In-Reply-To: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org>
References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org>
"Chris Gernon" <kabigon@gmail.com> writes:
> CREATE TABLE t (
> id serial,
> f double precision,
> CONSTRAINT t_pk PRIMARY KEY (id)
> );
> INSERT INTO t (f) VALUES (0.0000000000000000000000000000000563219288);
> ----------------------------------------
> SELECT to_char(f,
> 'FM999990.99999999999999999999999999999999999999999999999999') FROM t WHERE
> id = 1;
> Expected Output:
> 0.0000000000000000000000000000000563219288
> Actual Output:
> 0.
My immediate reaction to that is that float8 values don't have 57 digits
of precision. If you are expecting that format string to do something
useful you should be applying it to a numeric column not a double
precision one.
It's possible that we can kluge things to make this particular case work
like you are expecting, but there are always going to be similar-looking
cases that can't work because the precision just isn't there.
(In a quick look at the code, the reason you just get "0." is that it's
rounding off after 15 digits to ensure it doesn't print garbage. Maybe
it could be a bit smarter for cases where the value is very much smaller
than 1, but it wouldn't be a simple change.)
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, kabigon@gmail.com
Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values
In-Reply-To: <11125.1316540968@sss.pgh.pa.us>
References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org> <11125.1316540968@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox