C++ printf 带有 %f 但针对用户所在国家/地区进行了本地化

发布于 2024-12-08 18:22:08 字数 184 浏览 5 评论 0原文

我使用以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-12-15 18:22:08

基数字符(即“.”或“,”)由当前区域设置定义。默认区域设置(至少对于 Windows 系统)是“C”,它定义了“.”。作为基数字符。

您可以使用 setlocale 函数设置 C/C++ 程序的当前区域设置。

要将区域设置设置为当前系统/用户区域设置,可以使用以下语句:

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

请参阅 此处(参见链接页面上的示例...)了解有关 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:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文