From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Francisco Olarte <folarte(at)peoplecall(dot)com> |
Cc: | Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Suppress decimal point like digits in to_char? |
Date: | 2016-03-14 15:22:38 |
Message-ID: | CAKFQuwZdHN3K_0sFiU04zTQreWFrVubZsRGDODUpa68mwJzQoA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Mar 14, 2016 at 3:31 AM, Francisco Olarte <folarte(at)peoplecall(dot)com>
wrote:
> Hi;
>
> On Mon, Mar 14, 2016 at 2:53 AM, David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> > On Sunday, March 13, 2016, Ken Tanzer <ken(dot)tanzer(at)gmail(dot)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:
http://www.postgresql.org/docs/9.5/interactive/functions-string.html
format(formatstr text [, formatarg "any" [, ...] ])
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Joshua D. Drake | 2016-03-14 15:25:28 | Re: enum bug |
Previous Message | Merlin Moncure | 2016-03-14 14:32:07 | Re: Unexpected result using floor() function |