You can do all that using simple printf format strings
However the flags are an extension of the standard and documentation is difficult to come by.
In order to use the thousands separator flag, which is a single-quote ( ' ) you have to set the locale. C has its own default locale but it contains no thousands separator. The easiest way to go about setting the locale is to let the function figure out which one to use:
Code:
#include <locale.h>
...
setlocale(LC_ALL, "");
After that the thousands separator will work (and it will be correctly based on the user's language settings, too!).
As for the decimal, that's done with the "." modifier - that's part of the standard and is pretty well documented if you aren't already familiar with it.
And the dollar sign can just be before the formatting part for the number. If you want to be agnostic you can make a call to localeconv() and find out what the local currency sign is.
So, the general purpose printing function is this:
Code:
#include <locale.h>
#include <stdio.h>
...
struct lconv *locale;
setlocale(LC_ALL,"");
locale = localeconv();
float value = 1234.567;
printf("%s%'.2f\n", locale->currency_symbol, value);
I'm feeling very generous today, I guess.