[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf issue with thousands separator
From: |
Martin Michel |
Subject: |
Re: printf issue with thousands separator |
Date: |
Tue, 5 Jul 2022 21:53:41 +0200 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
Hi Jürgen,
> I believe I understood your problem now. As far as ⎕FIO is concerned it
> should be fixed
> in SVN 1579:
Many thanks, it's very impressive how fast you have implemented this
change!
> There could be a misunderstanding as to how 'Format by example' works (and
> that misunderstanding
> might also be caused by my testcases). What the APL2 calls a left or right
> "decorator" is not intended
> as an arbitrary string in the printf() fashion, but something that is
> directly attached (and possibly
> suppressed) to a number. In most cases the left decorator is either the minus
> sign or the overbar and
> the right decorator is not used. The rare exceptions where the right
> decorator is used are:
Yes, definitely a misunderstanding on my side (but not triggered by your
testcases, I started with format by example reading 'APL2 at a Glance'
and the IBM Language Reference). I thought "decorators" are any
characters except the control characters '[0-9],.', in a similar fashion
like printf can be used. Now your explanation makes sense and fully
explains the strange behaviour I was experiencing.
> The problem with ⎕FIO was actually caused by glibc which apparently ignores
> the ' flag even
> if the locale tells otherwise, On my machine (and in plain C):
>
> int
> main(int argc, char *argv[])
> {
> printf("%'f\n", 555555.66);
> }
>
> prints:
>
> 555555.660000
>
> I did already pass the ' flag to sprintf() in glibc but glibc then simply
> ignored it.
Same thing on my machine, after some research I found that having the
thousands separator depends on the LC_NUMERIC part of the locale. POSIX
locale does not use a grouping character. But this works:
#include <locale.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
if (!setlocale (LC_NUMERIC, "en_US.UTF-8"))
{
fprintf (stderr, "Locale not found.\n");
return 1;
}
printf ("%'f\n", 555555.66);
return 0;
}
Different results for de_DE, nl_NL etc. though!
Kind regards,
Martin
- printf issue with thousands separator, Martin Michel, 2022/07/04
- Re: printf issue with thousands separator, Dr . Jürgen Sauermann, 2022/07/04
- Re: printf issue with thousands separator, Martin Michel, 2022/07/05
- Re: printf issue with thousands separator, Dr . Jürgen Sauermann, 2022/07/05
- Re: printf issue with thousands separator,
Martin Michel <=
- Re: printf issue with thousands separator, Christian Robert, 2022/07/05
- Re: printf issue with thousands separator, Dr . Jürgen Sauermann, 2022/07/06
- Re: printf issue with thousands separator, Blake McBride, 2022/07/06
- Re: printf issue with thousands separator, Dr . Jürgen Sauermann, 2022/07/06
- Re: printf issue with thousands separator, Blake McBride, 2022/07/06