The definition of the mantissa will be amended to provide accurate results, as well as the example fixed. In addition, certain terms like maximum integer/fraction and minimum integer/fraction will be defined to support the definition
FULL PRODUCT VERSION :
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The documentation of DecimalFormat contains an example for engineering notation:
12345 formatted with "##0.##E0" is "12.3E3"
But instead of 12.3E3 the output is 12.345E3.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Format 12345 with pattern ##0.##E0
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output: 12.3E3
ACTUAL -
Output: 12.345E3
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
import java.util.Locale;
import java.util.Objects;
public class Tst
{
public static void main(String[] args)
{
Locale.setDefault(Locale.ENGLISH);
DecimalFormat df = new DecimalFormat("##0.##E0");
String realOutput = df.format(12345);
String expected = "12.3E3";
System.out.println(realOutput);
if (Objects.equals(realOutput, expected))
{
System.out.println("OK");
}
else
{
System.err.println("Formatted output " + realOutput + " differs from documented output " + expected);
}
}
}
---------- END SOURCE ----------
FULL PRODUCT VERSION :
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The documentation of DecimalFormat contains an example for engineering notation:
12345 formatted with "##0.##E0" is "12.3E3"
But instead of 12.3E3 the output is 12.345E3.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Format 12345 with pattern ##0.##E0
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output: 12.3E3
ACTUAL -
Output: 12.345E3
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
import java.util.Locale;
import java.util.Objects;
public class Tst
{
public static void main(String[] args)
{
Locale.setDefault(Locale.ENGLISH);
DecimalFormat df = new DecimalFormat("##0.##E0");
String realOutput = df.format(12345);
String expected = "12.3E3";
System.out.println(realOutput);
if (Objects.equals(realOutput, expected))
{
System.out.println("OK");
}
else
{
System.err.println("Formatted output " + realOutput + " differs from documented output " + expected);
}
}
}
---------- END SOURCE ----------
- csr for
-
JDK-8308317 Engineering notation of DecimalFormat does not work as documented
-
- Closed
-
- relates to
-
JDK-6282188 [Fmt-Nu]DecimalFormat - javadocs for section "Scientific Notation" and "Special Values" is not clear
-
- Resolved
-