C / C ++: printf uses commas instead of periods as decimal separator

I need my program to show the result using commas as a decimal separator.

From this link: http://www.java2s.com/Code/Java/Development-Class/Floatingpointwithcommasf.htm you can use something like this in Java:

System.out.printf("Floating-point with commas: %,f\n", 1234567.123);

      

Is there a flag or something that I can use to have similar behavior in C?

Thanks in advance!

+3


source to share


2 answers


If you want, you can set the current locale at the beginning of your program:



#include <stdio.h>
#include <locale.h>


int main()
{
    setlocale(LC_NUMERIC, "French_Canada.1252"); // ".OCP" if you want to use system settings
    printf("%f\n", 3.14543);
    return 0;
}

      

+17


source


There is C

no similar functionality. You can use sprintf

to print to char array and then replace semicolon manually. I cannot think of a better solution, sorry.



EDIT: Thanks to Matz Patersson: It seems that setting the language might change this character. Please see the link he posted.

+4


source







All Articles