You could always use the locale feature of printf.
Code:
#include <stdio.h>
#include <math.h>
#include <locale.h>
int main(int argc, char *argv[])
{
char *p = setlocale(LC_NUMERIC,argv[1]);
if ( p ) {
int num = 123456789;
printf("%s %'d\n", argv[1], num );
}
return 0;
}
Run with all the available locales
Code:
$ locale -a | while read line ; do ./a.out $line ; done
C 123456789
C.UTF-8 123456789
en_AG 123,456,789
en_AG.utf8 123,456,789
en_AU.utf8 123,456,789
en_BW.utf8 123,456,789
en_CA.utf8 123,456,789
en_DK.utf8 123.456.789
en_GB.utf8 123,456,789