pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Vincent Veyron <vv.lists@wanadoo.fr>
To: pgsql-general@postgresql.org
Subject: Re: unexpected character used as group separator by to_char
Date: Wed, 10 Mar 2021 09:41:19 +0100
Message-ID: <194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at> (raw)
In-Reply-To: <20210309212821.437795da590228b5c552eead@wanadoo.fr>
References: <20210309212821.437795da590228b5c552eead@wanadoo.fr>

On Tue, 2021-03-09 at 21:28 +0100, Vincent Veyron wrote:
> I'm having a problem with to_char() inserting unexpected characters as group separator.
> 
> For the record below, I wish to display 'credit' properly formated in an html form, using to_char(credit, 'FM999G990D00') 
> 
> SELECT *, to_char(credit, 'FM999G990D00') as yo from tblprospect_balance where id_item = 33;
> 
>  id_prospect | id_item | date_item  | libelle | debit | credit  | lettrage | id_facture |    yo    
> -------------+---------+------------+---------+-------+---------+----------+------------+----------
>          385 |      33 | 2021-03-09 | yo man  |  0.00 | 2345.10 |          |          8 | 2 345,10
> 
> The numbers are properly displayed in the html form. However, updating the record requires
>  the user to manually delete the space in '2 345,10', otherwise the last digit is lost.
>  Typing numbers including a group separator using the space bar works fine.
> 
> I exported the record to a text file and inspected it with emacs in hexadecimal mode :
> 
> 3338 3509 3333 0932 3032 312d 3033 2d30  385.33.2021-03-0
> 00000010: 3909 796f 206d 616e 0930 2e30 3009 3233  9.yo man.0.00.23
> 00000020: 3435 2e31 3009 0938 0932 e280 af33 3435  45.10..8.2...345
> 00000030: 2c31 300a                                ,10.
> 
> As you can see, the space in field 'libelle' (yo man) is different from the one in field 'yo' (2...345,10)
> 
> What can I do to get a standard space as group separator for my numbers?
> 
> #### system information ########
> I use postgresql 11.9 on Debian buster
> 
> My settings are : 
> 
> show lc_numeric;
>  lc_numeric  
> -------------
>  fr_FR.UTF-8

That "space" is UNICODE U+202F ("Narrow No-Break Space"), and that's what your
C library thinks to be the correct group separator for the French language.

You can either replace the character:

  SELECT replace(to_char(2345.10, 'FM999G990D00'), E'\u202F', ' ');

or you can choose a different locale that uses a different group separator
(not sure if that exists).

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (13+ messages)  latest in thread

Message-ID: <194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at>
Permalink:  ../194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at/
Also on:    postgresql.org/message-id/194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, vv.lists@wanadoo.fr
  Subject: Re: unexpected character used as group separator by to_char
  In-Reply-To: <194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at>
  References: <20210309212821.437795da590228b5c552eead@wanadoo.fr> <194db61d0b7d306e4416626a7d8205bc74c059ab.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox