Re: format integer

From: Steve Midgley <science(at)misuse(dot)org>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "ml(at)ft-c(dot)de" <ml(at)ft-c(dot)de>, "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: format integer
Date: 2021-01-24 16:37:43
Message-ID: CAJexoSLvrRxJrw6zEPU0-Xms0OBEeBFmXQ6HOgc8JMYw-36mjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Jan 24, 2021 at 8:06 AM David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> 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.
>
> I've had to deal with something similar in the past, strangely. My
solution was to convert the numeric formats to strings, and process there
to get the right rule set regarding number of digits (and preserving all
digits left of the period where required). Then convert back to your
original numeric format. The one thing I'd mention as an edge case is that
not all number systems use period as the significant digit delimiter, so be
sure you guarantee the number formatting when you convert to string is what
you expect when using this approach. I'd guess you could also solve this
with logic and math (floor/ceiling/modulus, etc) but I found that using
strings and regex was much easier for me.

Steve

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Torge Kummerow 2021-01-24 16:48:11 Re: format integer
Previous Message David G. Johnston 2021-01-24 16:06:27 Re: format integer