Printing a float with commas in C [duplicate]
This question already has an answer here : Closed 6 years ago . Possible Duplicate: Output 1000000 as 1,000,000 and so on I have a float variable in the format xxxxxxxx.xx (Eg. 11526.99). I'd like to print it as 11,562.99 with a comma. How can I insert a comma in C? Try: #include <locale.h> #include <stdio.h> int main() { float f = 12345.67; // obtain the existing locale name for numbers char *oldLocale = setlocale(LC_NUMERIC, NULL); // inherit locale from environment setlocale(LC_NUMERIC, ""); // print number printf("%'.2f\n", f); // set the locale back setlocale(LC_NUMERIC, oldLocale); }