简体   繁体   English

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

[英]Use of locale-specific grouping separator in java Formatter

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. 我正在为SCJP学习,而我的书(塞拉利昂大学(Sierra))谈到Formatter类,我可以使用标志“,”来使用特定于语言环境的分组分隔符。 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? 我做错了什么?

  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. 您用于示例的数字小于1000,并且不需要千位分隔符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中提取特定于语言环境的格式的日期字段? - How to extract the date fields for locale-specific formatting in Java? GSON 默认日期序列化程序是特定于语言环境的 - GSON default date serializer is locale-specific 在特定于语言环境的错误消息中进行插值 - Interpolation in locale-specific error messages Java 8 和 11 之间相同区域设置的不同分组分隔符 - Different grouping separator for same Locale between Java 8 and 11 如何使注入的对象映射器 output 特定于语言环境 - How to make injected objectmapper output locale-specific 时间和日期的特定于语言环境的格式,包括毫秒 - Locale-specific formatting of time and date including milliseconds Java:语言环境是否会影响JFormattedTextField的格式化程序 - Java : Does Locale affect the Formatter for JFormattedTextField Java split(),使用包含特定字符的整个单词作为分隔符 - Java split(), use whole word containing a specific character as separator Java覆盖特定区域设置的区域设置 - Java override locale setting for specific locale 使用DecimalFormat Grouping Java时删除最后一个分组分隔符 - Remove the last grouping separator when using DecimalFormat Grouping java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM