Re: Suppress decimal point like digits in to_char?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Suppress decimal point like digits in to_char?
Дата
Msg-id CAKFQuwZdHN3K_0sFiU04zTQreWFrVubZsRGDODUpa68mwJzQoA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Suppress decimal point like digits in to_char?  (Francisco Olarte <folarte@peoplecall.com>)
Ответы Re: Suppress decimal point like digits in to_char?  (Francisco Olarte <folarte@peoplecall.com>)
Re: Suppress decimal point like digits in to_char?  (Ken Tanzer <ken.tanzer@gmail.com>)
Список pgsql-general
On Mon, Mar 14, 2016 at 3:31 AM, Francisco Olarte <folarte@peoplecall.com> wrote:
Hi;

On Mon, Mar 14, 2016 at 2:53 AM, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> On Sunday, March 13, 2016, Ken Tanzer <ken.tanzer@gmail.com> wrote:
....
> Typically if I'm going to format any currency amount with pennies I would
> format all values, even those with zero pennies, to the same precision.
> Typically when displaying such amounts I'd right-justify the values and thus
> cause the decimals to line up.

But a right-aligning string output routine needs to be used.


cdrs=> select val, tc, '"'||tc||'"' as quoted,
'"'||regexp_replace(tc,'\.$','   ')||'"' as replaced from (select val,
to_char(val::decimal(6,2),'FM999,990D99') as tc from (values
(1234),(1.05),(0)) as v(val)) as w;
 val  |   tc   |  quoted  |  replaced
------+--------+----------+------------
 1234 | 1,234. | "1,234." | "1,234   "
 1.05 | 1.05   | "1.05"   | "1.05"
    0 | 0.     | "0."     | "0   "
(3 rows)

Summarising, any combination can be easily done with a single round of replace.


​See also:


format(formatstr text [, formatarg "any" [, ...] ])

​David J.​


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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Unexpected result using floor() function
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: enum bug