BUG #6217: to_char() gives incorrect output for very small float values - Mailing list pgsql-bugs

From Chris Gernon
Subject BUG #6217: to_char() gives incorrect output for very small float values
Date
Msg-id 201109201717.p8KHHlZU087195@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #6217: to_char() gives incorrect output for very small float values  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Re: BUG #6217: to_char() gives incorrect output for very small float values  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      6217
Logged by:          Chris Gernon
Email address:      kabigon@gmail.com
PostgreSQL version: 9.1.0
Operating system:   Windows XP
Description:        to_char() gives incorrect output for very small float
values
Details:

The to_char() function gives incorrect output for float values whose decimal
expansion has several digits (more than somewhere around 14-15) after the
decimal point.

To reproduce:

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.

----------------------------------------


SELECT to_char(f,
'999990.99999999999999999999999999999999999999999999999999') FROM t WHERE id
= 1;

Expected Output:
     0.00000000000000000000000000000005632192880000000000

Actual Output:
      0.00000000000000

----------------------------------------

pgsql-bugs by date:

Previous
From: "Lionel Elie Mamane"
Date:
Subject: BUG #6216: Calling PQconnectdbParams from C++ with a char**
Next
From: "Kevin Grittner"
Date:
Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values