agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: ml@ft-c.de
To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
Subject: Re: format integer
Date: Sun, 24 Jan 2021 18:35:15 +0100
Message-ID: <5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de> (raw)
In-Reply-To: <CAKFQuwZ8si84Z3wVFJrHMQ10A_qiJ3CEnA6qfYsen=DsoVEY+g@mail.gmail.com>
References: <f3f20234950352a5342a3f6d7fc96eca1f8ebba6.camel@ft-c.de>
	<CAKFQuwZ8si84Z3wVFJrHMQ10A_qiJ3CEnA6qfYsen=DsoVEY+g@mail.gmail.com>

On Sun, 2021-01-24 at 09:06 -0700, David G. Johnston wrote:
> 
> On Sunday, January 24, 2021, <ml@ft-c.de> 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








view thread (5+ messages)

Message-ID: <5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de>
Permalink:  ../5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de/
Also on:    postgresql.org/message-id/5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ml@ft-c.de, pgsql-sql@lists.postgresql.org
  Subject: Re: format integer
  In-Reply-To: <5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox