octave-maintainers
[Top][All Lists]
Advanced

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

Re: printf and locale


From: Pascal Dupuis
Subject: Re: printf and locale
Date: Sat, 23 Feb 2013 22:00:41 +0100

2013/2/23 Daniel J Sebald <address@hidden>:

>
> It's a tricky problem.  To convert 0,50000 back to 0.50000 is difficult
> after the fact because it requires context; so that's not a good way to go.
> That means
>
> 1) At the point of translating the float machine representation into ASCII
> there needs to be a test of the locale flag and conditional tests on what
> the output destination is.
>
> or
>
> 2) Just before displaying to the screen a routine could scan the output line
> and convert and decimal points to commas.
>
> #1 is bad in the sense that it runs against the paradigm of generating
> output which can be redirected.  #2 is sort of clumsy or may not cover all
> basis (i.e., is the command line/pager output the only place where
> decimal-point should be translated to a comma-point?).
>
> Dan

I introduced the first version of the 'locale' patch in the context of
reading CSV files produced on a machine with french locales and for
which I had no admin access.

I'm still concerned today. Working in France, the contracts with
software vendors request that software are as far as possible
translated in French. This sometimes becomes problematic. The last
problem I had was to send parameters to a measuring device working in
Lua. The hardware had no room for French support, the comma used as
decimal separator was understood as argument separator :-)

LabView has some kind of way to impose how to format numbers, I don't
know if it is an extension or something general:
printf("%.;%f", a) forces the use of point as decimal separator;
printf("%,;%f", a) forces the use of the comma as decimal separator.

I agree that the full locale support is tricky, because every software
in the call chain must use  the same locale (and be locale-aware). I
propose the following approach as possible workaround:
1) implement the '%.;%f' and '%,;%f' method on scanf and printf
2) disable locale support on printf, except if explicitelly required
during the configure stage. In this case, display a message about
possible issues with other software like gnuplot. Ask people to find
where the problem occurs and to submit patches.

This way:
1) if people do not enable locale support on printf, they still have
some mean of choosing between comma and point as decimal separator
2) if they choose to enable it, they are warned about problems.

Regards

Pascal


reply via email to

[Prev in Thread] Current Thread [Next in Thread]