Re: Suppress decimal point like digits in to_char?

Поиск
Список
Период
Сортировка
От Ken Tanzer
Тема Re: Suppress decimal point like digits in to_char?
Дата
Msg-id CAD3a31Ws457FCUhwmrM7CNeUZk7RE8TnLunyFP-Kd_zcP03Vag@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Suppress decimal point like digits in to_char?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Suppress decimal point like digits in to_char?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general


On Mar 13, 2016 6:29 PM, "David G. Johnston" <david.g.johnston@gmail.com> wrote:
>
> 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.

Thanks David. Just curious what part of this you would question.  The case for numbers, currency in particular, coming out with a decimal and pennies when present, and as whole dollars when not (and without a decimal place at the end) seems pretty common and clear cut.  What am I missing in your question?

Cheers,
Ken

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Suppress decimal point like digits in to_char?
Следующее
От: Tom Smith
Дата:
Сообщение: retrieve grouping sets/rollup rows