Re: Suppress decimal point like digits in to_char? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Suppress decimal point like digits in to_char?
Date
Msg-id CAKFQuwa+Mz0QQe0ZdfhAw5G0+5C70xDHgsZvRzm8tHeO5zWCGQ@mail.gmail.com
Whole thread Raw
In response to Suppress decimal point like digits in to_char?  (Ken Tanzer <ken.tanzer@gmail.com>)
Responses Re: Suppress decimal point like digits in to_char?  (Ken Tanzer <ken.tanzer@gmail.com>)
List pgsql-general
On Sunday, March 13, 2016, Ken Tanzer <ken.tanzer@gmail.com> wrote:
Hi.  Is there a way with to_char to suppress a decimal point, like a leading or trailing 0, so that integers will not have them, but non-ints will?  I'm hoping I'm missing something easy.  Thanks.

Ken

SELECT val,to_char(val::decimal(6,2),'FM999,999D99') FROM
( SELECT 1 AS val UNION SELECT 1.05 AS val) foo;

 val  | to_char 
------+---------
    1 | 1.
 1.05 | 1.05



Not seeing a native way to do so - and I'd question doing so as a general rule - though you know your domain.  If you must have this you will want to utilize regexp_replace to identify the situation and replace it.  A simple "\.$" check and a substring would work also.

David J.

pgsql-general by date:

Previous
From: Ken Tanzer
Date:
Subject: Suppress decimal point like digits in to_char?
Next
From: Ken Tanzer
Date:
Subject: Re: Suppress decimal point like digits in to_char?