Обсуждение: GetValue(), floats, and locales

Поиск
Список
Период
Сортировка

GetValue(), floats, and locales

От
"Jeroen T. Vermeulen"
Дата:
I just got a bothersome bug report from a libpqxx user in Hungary (where,
as it turns out, floating-point numbers are written with decimal commas
rather than decimal points).  It appears that libpq's GetValue() delivers
floating-point fields in localized format.  The problem with this is that
libpqxx then tries to parse the numbers using sscanf(), which apparently
doesn't expect the number to have a decimal comma.

This begs the question: is it libpq that represents these values using the
client's locale, or does the server ship them in this form according to
its own locale?  The former is fine but really needs (1) some standard
way to parse the localized numbers, or (2) a bypass to the more parsable 
C-style representation.  The latter would be just plain crazy AFAICS.


Jeroen



Re: GetValue(), floats, and locales

От
Tom Lane
Дата:
"Jeroen T. Vermeulen" <jtv@xs4all.nl> writes:
> I just got a bothersome bug report from a libpqxx user in Hungary (where,
> as it turns out, floating-point numbers are written with decimal commas
> rather than decimal points).  It appears that libpq's GetValue() delivers
> floating-point fields in localized format.  The problem with this is that
> libpqxx then tries to parse the numbers using sscanf(), which apparently
> doesn't expect the number to have a decimal comma.

> This begs the question: is it libpq that represents these values using the
> client's locale, or does the server ship them in this form according to
> its own locale?

The server should always ship floats in "standard" representation.
AFAIK the only way to use localized numeric representations is to
write to_char() and to_number() calls (or use the money datatype).
If you can show us a case where plain float display does the other,
it's a bug.

libpq is not doing anything to you, in any case: it's far too stupid
to convert data at all ;-)
        regards, tom lane



Re: GetValue(), floats, and locales

От
"Jeroen T. Vermeulen"
Дата:
On Wed, May 07, 2003 at 12:19:02PM -0400, Tom Lane wrote:
> 
> The server should always ship floats in "standard" representation.
> AFAIK the only way to use localized numeric representations is to
> write to_char() and to_number() calls (or use the money datatype).
> If you can show us a case where plain float display does the other,
> it's a bug.

I personally can't show you anything except a bug report from my user,
but I'll encourage him to post it here.  He complains that libpqxx can't
read the fraction part of a floating-point number, which boils down to a
sscanf(GetValue(c,x,y), "%f", &f) always returning f as an integral 
value.

Of course it's also possible that there's a bug in his display code or
that I'm missing something very, very important.  Time to add some FP
test cases...


Jeroen



Re: GetValue(), floats, and locales

От
"Jeroen T. Vermeulen"
Дата:
On Wed, May 07, 2003 at 06:40:25PM +0200, Jeroen T. Vermeulen wrote:
> 
> Of course it's also possible that there's a bug in his display code or
> that I'm missing something very, very important.  Time to add some FP
> test cases...

Turned out to be a problem in communication: GetValue() doesn't heed
locales (which is good and proper), but my sscanf() does and that's where
the problem lies.


Jeroen