char *double2comma(double f, int places) { static char tmp[40]; char *s; int i=0; if ((places < 0) || (places > 38)) { tmp[0] = 0; return tmp; } sprintf(tmp, "%#.*f", places, f); s = strchr(tmp, '.'); if (!places) { /* Get rid of trailing '.': */ *s = '\0'; } while(--s > tmp) { if (i++ == 2) { /* Are we just to the right of '-'? */ if (s[-1] == '-') break; /* Insert a comma */ i=0; /* Shift segment right to make room for ',': */ memmove(s+1, s, strlen(s)+1); *s = ','; } } return tmp; } usage: printf("You have $%s in your account.", double2comma((double)123.45, 2));