在 java Formatter 中使用特定于语言环境的分组分隔符

发布于 2024-10-08 00:48:16 字数 314 浏览 1 评论 0原文

我正在学习 SCJP,我的书(Sierra 的)提到 Formatter 类,我可以使用标志“,”来使用特定于区域设置的分组分隔符。如果我理解得很好,这行代码:

System.out.printf("%2$,f + %1$,f", 123.7, 456.2);

应该产生:

456,200000 + 123,700000

带逗号,但它实际上产生:

456.200000 + 123.700000

我做错了什么?

I'm studying for SCJP, and my book (Sierra's) says about the Formatter class that I can use the flag "," to use locale-specific grouping separator. If I understand well, this line of code:

System.out.printf("%2$,f + %1$,f", 123.7, 456.2);

should produce:

456,200000 + 123,700000

with comma, but it's actually producing:

456.200000 + 123.700000

What I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

假扮的天使 2024-10-15 00:48:16
  System.out.printf("%2$,f + %1$,f", 1232.7, 4562343.2);

将为您提供

4,562,343.200000 + 1,232.700000

示例中使用的数字小于 1000,并且不需要千位分隔符。

  System.out.printf("%2$,f + %1$,f", 1232.7, 4562343.2);

will give you

4,562,343.200000 + 1,232.700000

The numbers you are using for your example are less than 1000 and do not need thousand separators.

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