If your printf supports the '
flag (as required by POSIX 2008 printf()
), you can probably do it just by setting your locale appropriately. Example:
#include <stdio.h>
#include <locale.h>
int main(void)
{
setlocale(LC_NUMERIC, "");
printf("%'d
", 1123456789);
return 0;
}
And build & run:
$ ./example
1,123,456,789
Tested on Mac OS X & Linux (Ubuntu 10.10).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…