我需要我的程序使用逗号作为小数分隔符显示输出.
根据这个链接:http://www.java2s.com/Code/Java/Development-Class/Floatingpointwithcommasf.htm你可以在Java中使用这样的东西:
System.out.printf("Floating-point with commas: %,f\n", 1234567.123);
Run Code Online (Sandbox Code Playgroud)
是否有标志或其他东西我可以用来在C中有类似的行为?
提前致谢!
Nem*_*ric 19
如果需要,可以在程序开头设置当前区域设置:
#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;
}
Run Code Online (Sandbox Code Playgroud)
中没有类似的功能C。您可以使用sprintf打印到字符数组中,然后手动将点替换为逗号。我想不出更好的解决办法,抱歉。
编辑:感谢 Mats Patersson 的评论:似乎设置区域设置可以更改此字符。请看一下他发布的链接。