Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltFS3-0005hZ-H5 for pgsql-general@arkaria.postgresql.org; Tue, 15 Jun 2021 20:14:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ltFS2-0002Lc-IC for pgsql-general@arkaria.postgresql.org; Tue, 15 Jun 2021 20:14:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltFS2-0002LR-7A for pgsql-general@lists.postgresql.org; Tue, 15 Jun 2021 20:14:22 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ltFS0-0006Qq-7T for pgsql-general@lists.postgresql.org; Tue, 15 Jun 2021 20:14:21 +0000 Received: by mail-oi1-x22d.google.com with SMTP id q10so15362894oij.5 for ; Tue, 15 Jun 2021 13:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=a8eI177bs+FxuBtU+f5gEoJRlIS94UvKDzNQ82iVvXY=; b=ls9wzfV4vr6sawuz4KfwxIBE2YOIue7sg1xHt3H9jMhB8uU6HszO7hx7Di2NflMP8V pj+M2hGeCZUM+9d1y14SgkNUutKLcwdgThx3h7D4PGEIR49/o+c6m1VwNiiuDaJu7ixj d6pZ4fo9TUS58ZX6/jYUfvaPA9Weq79o+kETsmSJkNZ+2CxQKRjgfXYMDiuEFwPgm0re yr4OeltyWeHMIvh9mZcnSucZ66JSR+/bRxopRyEzOvGOhube4Pc16zqwl6vyazg/OQW7 08X7yX10FfYo1JJ8sCx7fCYj2Ojt5jjmfQ/yc4EoAmhQ5t+FEKV/0P1Sjli1P3OpLPth KA8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=a8eI177bs+FxuBtU+f5gEoJRlIS94UvKDzNQ82iVvXY=; b=qTa4S3r7w8thXtQI/XvoiFAJ0nBc+VIqtw37Pn8rxe/SNotS777bEjoGym1vlxrjQA wO5RUgrzFZ1r1zH5g+W8Pw/3lWNHTeZ5ir4zK1wQl6iVGZEHetTzk2DMpC66IWkS95Gz KsP5i8TPdKD2r2gs7UPTZAc6g7AsVj3rBsoOG43Y7/6D1I2iKP2JdhOQhjC/+DTNlXuK dnwnl3GLOGWv1Y1De54mhGNZdK5l6cOux2CGDt57uZSXHt4Y+sexTfbrsauukFb0NPqH eQJ26vEI2IppPjMFdDPySwyRwIFPp7PZymLzdZEDeTMwSvaYPgGYWz7ZzMhG9U2P9OOj 1kiQ== X-Gm-Message-State: AOAM530N5q+9HcarNKjSbG3odT9KeuAid69vlj+Hxn2mEspLsKwFTMhm p6pPFN0+T7L/Cb+fL4KDps4V/3nz0PJQlw== X-Google-Smtp-Source: ABdhPJzrz7Kgo+TSp+BivIDF+Fwwte1eO5ux0zL6j2Mbi/7L+EK6Kk2lVZ8HONZReUPA5EqNr7NZXQ== X-Received: by 2002:aca:4482:: with SMTP id r124mr578089oia.153.1623788057870; Tue, 15 Jun 2021 13:14:17 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id w4sm4362609otm.31.2021.06.15.13.14.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 13:14:17 -0700 (PDT) Subject: Re: CONCAT function adding extra characters To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Tue, 15 Jun 2021 15:14:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------515B97B323C3377CCD36150D" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------515B97B323C3377CCD36150D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------515B97B323C3377CCD36150D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.
--------------515B97B323C3377CCD36150D--