Suppress decimal point like digits in to_char?

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Suppress decimal point like digits in to_char?
Date: 2016-03-13 23:16:21
Message-ID: CAD3a31U8ZwsjcTxpM=ATtv2XLKO=id2kKQgDaOu9+51nBxsQig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

--
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://agency-software.org/demo/client
<https://agency-software.org/demo/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801

Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-03-14 01:29:03 Re: Suppress decimal point like digits in to_char?
Previous Message Melvin Davidson 2016-03-13 22:15:58 Re: Distributed Table Partitioning