Re: format integer - Mailing list pgsql-sql

From Steve Midgley
Subject Re: format integer
Date
Msg-id CAJexoSLvrRxJrw6zEPU0-Xms0OBEeBFmXQ6HOgc8JMYw-36mjw@mail.gmail.com
Whole thread Raw
In response to Re: format integer  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-sql


On Sun, Jan 24, 2021 at 8:06 AM David G. Johnston <david.g.johnston@gmail.com> 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.

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

pgsql-sql by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: format integer
Next
From: Torge Kummerow
Date:
Subject: Re: format integer