On Tue, 29 Aug 2023 18:02:51 GMT, Naoto Sato <na...@openjdk.org> wrote:

>> Please review this PR and [CSR](https://bugs.openjdk.org/browse/JDK-8314607) 
>> which clarifies the behavior of patterns  in regards to the max integer 
>> digits in j.text.DecimalFormat.
>> 
>> The current specification (of `applyPattern`) states that patterns do not 
>> set the value of max integer digits. This is incorrect, these 
>> methods/constructors do set a value for the max integer digits. If the 
>> pattern is in scientific notation, the max integer digits value is derived 
>> from the pattern. Otherwise, the pattern is ignored, and the limit is set to 
>> `Integer.MAX_VALUE`.
>> 
>> See below,
>> 
>> DecimalFormat df = new DecimalFormat();
>> df.applyPattern("000.000E0");
>> df.getMaximumIntegerDigits(); //  ==> 3
>> df.applyPattern("000.000");
>> df.getMaximumIntegerDigits(); // ==> 2147483647
>> 
>> DecimalFormat df = new DecimalFormat("000.000");
>> df.getMaximumIntegerDigits(); // ==> 2147483647
>> DecimalFormat df = new DecimalFormat("000.000E0");
>> df.getMaximumIntegerDigits(); // ==> 3
>> 
>> 
>> Method descriptions should be fixed, and the relevant constructors need to 
>> mention the behavior as well.
>
> src/java.base/share/classes/java/text/DecimalFormat.java line 458:
> 
>> 456:      * is the typical end-user desire. Use {@link 
>> #setMaximumIntegerDigits(int)}
>> 457:      * if you want to set a specific limit to integer digits when the
>> 458:      * given pattern is not in scientific notation.
> 
> It could be simpler if the normal case (Integer.MAX_VALUE) comes first, then 
> the scientific notation case in which you can refer to the max integer digit 
> in the class description. Also, `setMaximumIntegerDigits` can be called on a 
> scientific notation as well, correct?

Thank you for the review. Will adjust with your suggestions.

> Also, `setMaximumIntegerDigits` can be called on a scientific notation as 
> well, correct?

I meant that you pretty much only need to consider calling 
`setMaximumIntegerDigits` when the pattern is not in scientific notation, not 
that you are not able to. Will make this clearer.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15349#discussion_r1309195909

Reply via email to