From: | ml(at)ft-c(dot)de |
---|---|
To: | "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: format integer |
Date: | 2021-01-24 17:35:15 |
Message-ID: | 5d7a256d68909160e27856244f56f1f5dd7db61e.camel@ft-c.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Sun, 2021-01-24 at 09:06 -0700, David G. Johnston wrote:
>
> On Sunday, January 24, 2021, <ml(at)ft-c(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Roberto Médola | 2021-01-29 16:47:37 | Re: Bring to dead tuples to alive |
Previous Message | Torge Kummerow | 2021-01-24 16:48:11 | Re: format integer |