C++ printf with

后端 未结 2 2049
青春惊慌失措
青春惊慌失措 2020-12-16 14:48

I\'m using the following C++ syntax to output a floating point value on a Windows platform:

printf(\"%.2f\", 1.5);

It works well if I run i

相关标签:
2条回答
  • 2020-12-16 15:29

    Try using setlocale() function http://www.cplusplus.com/reference/clibrary/clocale/setlocale/

    0 讨论(0)
  • 2020-12-16 15:35

    The radix character (i.e. '.' or ',') is defined by the current locale. The default locale (at least for Windows systems) is "C", which defines '.' as radix character.

    You can set the current locale for a C/C++ program using the setlocale function.

    To set the locale to the current system/user locale, you can use the following statement:

    #include <locale.h>
    setlocale(LC_ALL, ".OCP");
    

    See here (cf. the examples on the linked page...) for more information about setlocale

    0 讨论(0)
提交回复
热议问题