C / C ++:printf使用逗号而不是点作为小数点分隔符 [英] C/C++: printf use commas instead of dots as decimal separator
本文介绍了C / C ++:printf使用逗号而不是点作为小数点分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要我的程序使用逗号作为小数点分隔符来显示输出。
I need that my program shows the output using commas as decimal separator.
根据此链接:可以在Java中使用的http://www.java2s.com/Code/Java/Development-Class/Floatingpointwithcommasf.htm 像这样的东西:
According to this link: http://www.java2s.com/Code/Java/Development-Class/Floatingpointwithcommasf.htm you can use in Java something like this:
System.out.printf("Floating-point with commas: %,f\n", 1234567.123);
在C中是否存在标志或可用于类似行为的东西?
Is there a flag or something that I can use to have a similar behaviour in C?
谢谢!
推荐答案
如果需要,可以设置当前语言环境在程序开始时:
If you want, you can set 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;
}
这篇关于C / C ++:printf使用逗号而不是点作为小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文