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)
======================================================================
- duplicates
-
JDK-6609740 [Fmt-De] format error in DecimalFormat
- Resolved
-
JDK-6594713 [Fmt-De] DecimalFormat incorrectly formats values if the negative subpattern is (#)
- Closed