| hermann on Sun, 07 Jan 2024 17:42:42 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| printf "%'d" missing in Pari/GP for printing 1000s commas |
In C
setlocale(LC_NUMERIC, "");
printf("%'d\n", 1123456789);
outputs:
1,123,456,789
Pari/GP does not allow for that:
? printf("%'d",12345);
*** at top-level: printf("%'d",12345)
*** ^-------------------
*** printf: invalid conversion or specification ' in format `%'d'.
*** Break loop: type 'break' to go back to GP prompt
break>
For generating a markdown table with GP I used this simple function for
up to 9-digit numbers:
f(d)={if(d>999999,print1(d\1000000,",");d%=1000000;printf("%03d,%03d|",d\1000,d%1000),if(d>999,print1(d\1000,",");printf("%03d|",d%1000),print1(d,"|")));}
Is there a more general solution?
Regards,
Hermann.