Re: Zero-padding and zero-masking fixes for to_char(float) - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Zero-padding and zero-masking fixes for to_char(float)
Date
Msg-id 20150402181443.GD941@momjian.us
Whole thread Raw
In response to Re: Zero-padding and zero-masking fixes for to_char(float)  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
On Wed, Apr  1, 2015 at 11:48:37AM -0400, Bruce Momjian wrote:
> This should return something like 15555600000000.000... (per Oracle
> output at the URL above, float4 has 6 significant digits on my compiler)
> but I can't seem to figure how to get printf() to round non-fractional
> parts.  I am afraid the only solution is to use printf's %e format and
> place the decimal point myself.

Hearing nothing, I went with the %e approach;  patch attached.  The new
output looks right:

    test=> SELECT to_char(float4 '15555555555555.912345678912345678900000000000000000000000',
              repeat('9', 50) || '.' || repeat('9', 50));
                                                    to_char
    --------------------------------------------------------------------------------------------------------
                                          15555600000000.00000000000000000000000000000000000000000000000000
    (1 row)

> The fact I still don't have a complete solution suggests this is 9.6
> material but I still want to work on it so it is ready.

I will keep this patch for 9.6 unless I hear otherwise.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Abbreviated keys for Numeric
Next
From: Robert Haas
Date:
Subject: Re: Something is rotten in the state of Denmark...