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 1l3jIJ-00071Q-6i for pgsql-sql@arkaria.postgresql.org; Sun, 24 Jan 2021 17:35: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 1l3jIG-0007Pz-LB for pgsql-sql@arkaria.postgresql.org; Sun, 24 Jan 2021 17:35:20 +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 1l3jIG-0007Pr-Et for pgsql-sql@lists.postgresql.org; Sun, 24 Jan 2021 17:35:20 +0000 Received: from einhorn-mail-out.in-berlin.de ([217.197.80.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l3jIE-0007mZ-1J for pgsql-sql@lists.postgresql.org; Sun, 24 Jan 2021 17:35:19 +0000 X-Envelope-From: ml@ft-c.de X-Envelope-To: Received: from authenticated.user (localhost [127.0.0.1]) by einhorn.in-berlin.de with ESMTPSA id 10OHZFwT017713 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Sun, 24 Jan 2021 18:35:16 +0100 Message-ID: <5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de> Subject: Re: format integer From: ml@ft-c.de Reply-To: ml@ft-c.de To: "pgsql-sql@lists.postgresql.org" Date: Sun, 24 Jan 2021 18:35:15 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.0 FreeBSD GNOME Team MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, 2021-01-24 at 09:06 -0700, David G. Johnston wrote: > > On Sunday, January 24, 2021, wrote: > > > > I need a integer format with different decimal places > > The integer should have 6 diggits. (or 7 or 8) > >   > > > > No, there isn’t a function to apply this convoluted formatting rule > to non-integer numbers.  You will need to write your own. > > David J. > My idea is SELECT round(1.2345678912, 5 - least(log(1.2345678912)::int,5) ); SELECT round(12.345678912, 5 - least(log(12.345678912)::int,5) ); SELECT round(123.45678912, 5 - least(log(123.45678912)::int,5) ); SELECT round(1234.5678912, 5 - least(log(1234.5678912)::int,5) ); SELECT round(12345.678912, 5 - least(log(12345.678912)::int,5) ); SELECT round(123456.78912, 5 - least(log(123456.78912)::int,5) ); SELECT round(1234567.8912, 5 - least(log(1234567.8912)::int,5) ); SELECT round(12345678.912, 5 - least(log(12345678.912)::int,5) ); SELECT round(123456789.12, 5 - least(log(123456789.12)::int,5) ); as content for a function  with arguments (value numeric, diggits int) Have s.o. a better idea? Franz