From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: CONCAT function adding extra characters
Date: Tue, 15 Jun 2021 15:14:16 -0500
Message-ID: <b12a2a19-4290-b27a-5ab3-25ab82e1b0e2@gmail.com> (raw)
In-Reply-To: <CAGoODpdy0zyMbsOCb5n78yM4v2UvWeb2GT9WyCnH1YtSxkcYZA@mail.gmail.com>
References: <CAGoODpdy0zyMbsOCb5n78yM4v2UvWeb2GT9WyCnH1YtSxkcYZA@mail.gmail.com>
On 6/15/21 1:55 PM, AI Rumman wrote:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
> Result:
> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
Because of the well-known difficulty in precisely converting floating point
to decimal, in cases like this, I always cast to NUMERIC of the desired
precision. It's the COBOL programmer in me...
--
Angular momentum makes the world go 'round.
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-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: CONCAT function adding extra characters
In-Reply-To: <b12a2a19-4290-b27a-5ab3-25ab82e1b0e2@gmail.com>
References: <CAGoODpdy0zyMbsOCb5n78yM4v2UvWeb2GT9WyCnH1YtSxkcYZA@mail.gmail.com> <b12a2a19-4290-b27a-5ab3-25ab82e1b0e2@gmail.com>
* 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