Search Postgresql Archives

Re: to_char with locale decimal separator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/30/2013 08:34 AM, Ingmar Brouns wrote:


Thanks for your time, appreciate it! As a dirty alternative, you could also do
something like:

select translate(5.000::text,'.',substr(to_char(.0),2,1));

Not so nice, but would work. Though I still feel there should be a more
elegant of doing this...


Two issues.

1) Leading and trailing zeros tend to be a personal preference and what and how many, even more so. Pre-canned implementations for formatting seem to best guess. I could see where trying to cover every conceivable
possibility would get complex.

2) You where looking at converting variable precision values, not uncommon, but adds a layer of complexity. For instance using the Python locale module it is possible to have it format a number according to locale and have trailing zeros, but it will pad to the specified precision(6 by default). So you still need to track something, in this case precision.

You could take your quick and dirty solution and put it in a function(to_char_trailing(numeric) and hide the dirty part:)

--
Adrian Klaver
adrian.klaver@xxxxxxxxx


--
Adrian Klaver
adrian.klaver@xxxxxxxxx


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux