I believe I understood your problem now. As far as ⎕FIO is concerned it should be fixed
in SVN 1579:
"%'.2f" ⎕FIO.sprintf 1234567.89
1,234,567.89
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:
1. negative numbers printed in parentheses instead of a minus sign. Sometimes used in bookkeeping.
2. output of negative numbers in a different color (typically red) using VT100 escape sequences as
left and right decorators.
In the examples that you apparently tried there were 2 left decorators (one being the $
and the other being the minus sign) and Format by example simply does not allow that.
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.
Best Regards,
Jürgen
On 7/5/22 10:08 AM, Martin Michel
wrote:
Hi Jürgen, thanks for your quick reply.I will look into adding support for the thousands separator (but not supporting the locales nonsense). That is, the thousands separator will always be comma and not e.g. full-stop like in some countries and comma in others.That would be great and I fully agree, locales support would be too much of a requirement.BTW format by example should have done the job (see the APL2 language reference page 140): "5,555.50" ⍕ 1234.56 1,234.56Well, I tried this but it only works for the simpler cases. I could manage to format figures with the currency symbol on the right side but the format by examples falls short if I want it on the left, combined with negative numbers and also rounding (e.g. no decimal point in example spec). So this works: ' -1,555,555.40 $' ⍕ 123456.789 ¯987654.12 123,456.79 $ -987,654.12 $ But I have not found anything which would give me these results: $ +123,457 $ -987,654 As far as I have understood IBM APL2 Language Reference this is not possible with format by example. I would be happy if you can convince me otherwise, then I would indeed not need ⎕FIO. Kind regards, Martin