Name: yyT116575 Date: 12/19/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
DecimalFormat produces duplicate suffix when format includes exponent and suffix
The following code illustrates the bug
import java.text.*;
import.java.util.*;
public class DFTest {
public static void main(String args[]) {
String fmtreg = "##0.# mln;(##0.# mln)";
String fmtexp = "##0.#E0 mln;(##0.#E0 mln)";
double numbers[] = {123456.789,-123456.789,1234567.993,-1234567.993};
DecimalFormat dformreg = (DecimalFormat)NumberFormat.getInstance(Locale.US);
dformreg.applyPattern(fmtreg);
DecimalFormat dformexp = (DecimalFormat)NumberFormat.getInstance(Locale.US);
dformexp.applyPattern(fmtexp);
for (int j = 0; j < numbers.length; j++)
{
System.out.println(((DecimalFormat)dformreg).toPattern() + " -> " + dformreg.format(numbers[j]));
System.out.println(((DecimalFormat)dformexp).toPattern() + " -> " + dformexp.format(numbers[j]));
}
}
}
The above code produces the following output:
#0.# mln;(#0.# mln) -> 123456.8 mln
##0.#E0 mln;(##0.#E0 mln) -> 123.5E3 mln mln
#0.# mln;(#0.# mln) -> (123456.8 mln)
##0.#E0 mln;(##0.#E0 mln) -> (123.5E3 mln mln)
#0.# mln;(#0.# mln) -> 1234568 mln
##0.#E0 mln;(##0.#E0 mln) -> 1.235E6 mln mln
#0.# mln;(#0.# mln) -> (1234568 mln)
##0.#E0 mln;(##0.#E0 mln) -> (1.235E6 mln mln)
Note that the DecimalFormat instance that includes both an exponent and a
suffix produces a duplicate suffix.
(Review ID: 114039)
======================================================================