JDK-4395163 : [Fmt-Nu] Negative suffix ignored if negative subpattern doesn't match positive subpattern
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.3.0,1.4.2,5.0,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic,linux,windows_98,windows_xp
  • CPU: generic,x86
  • Submitted: 2000-12-05
  • Updated: 2017-05-31
  • Resolved: 2017-05-29
Related Reports
Duplicate :  
Duplicate :  
Description

Name: boT120536			Date: 12/05/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

The spec for DecimalFormat says that the negative subpattern is only used to
determine the prefix and suffix for negative numbers:

> That means that "#,##0.0#;(#)" produces precisely the same
> behavior as "#,##0.0#;(#,##0.0#)".

However, if you actually try this example, the negative suffix gets lost unless
the two subpatterns match.

import java.text.*;
public class PatternTest
{
	public static void main(String[] args)
	{
		DecimalFormat df = new DecimalFormat("#,##0.0#;(#,##0.0#)");
		System.out.println(df.toPattern());
		System.out.println(df.format(-1.5));
		
		DecimalFormat df2 = new DecimalFormat("#,##0.0#;(#)" );
		System.out.println(df2.toPattern());
		System.out.println(df2.format(-1.5));
	}
}

Output:
#,##0.0#;(#,##0.0#)
(1.5)
#,##0.0#;(#,##0.0#
(1.5
(Review ID: 108474) 
======================================================================

Comments
Duplicates 6609740
29-05-2017

EVALUATION Committed for Tiger. ###@###.### 2003-10-20
20-10-2003