C++ printf 带有 %f 但针对用户所在国家/地区进行了本地化
我使用以下 C++ 语法在 Windows 平台上输出浮点值:
printf("%.2f", 1.5);
如果我在英语用户帐户上运行它,效果很好。我的假设是,如果我在法国用户帐户上运行它,输出将是 1,50 而不是 1.50。
为什么我看不到它以及如何产生我想要的结果?
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 it on an English user account. My assumption was that if I run it on, say French user account, the output will be 1,50 instead of 1.50.
Why do I not see it and how to produce my desired result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基数字符(即“.”或“,”)由当前区域设置定义。默认区域设置(至少对于 Windows 系统)是“C”,它定义了“.”。作为基数字符。
您可以使用
setlocale
函数设置 C/C++ 程序的当前区域设置。要将区域设置设置为当前系统/用户区域设置,可以使用以下语句:
请参阅 此处(参见链接页面上的示例...)了解有关
setlocale
的更多信息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:
See here (cf. the examples on the linked page...) for more information about
setlocale
尝试使用 setlocale() 函数
http://www.cplusplus.com/reference/clibrary/clocale/setlocale/
Try using setlocale() function
http://www.cplusplus.com/reference/clibrary/clocale/setlocale/