-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArchiveUtils.doubleToString() rounding fails unit test under Java 8 #31
Comments
I'm confused - 12.35 is the correct answer for |
EDIT: I was mistake in the previous comment. The 12.35 figure is what I'd expect for normal rounding, but this class has long defaulted to From the Java 8 compatibility guidelines:
The related bug is here, but I'm not sure this can be responsible unless that fix broke the behaviour elsewhere. EDIT: That direct link to the bug doesn't seem to work, sometimes? You may have to go via the compatibility report page. |
Oh weird. Looks like they swapped an old bug for a new one!? Using this test class: import java.text.NumberFormat;
public class TestNumberFormatRounding {
public static void main(String[] args) {
System.out
.println("JVM Version: " + System.getProperty("java.version"));
NumberFormat nf = java.text.NumberFormat.getInstance();
nf.setMaximumFractionDigits(3);
nf.setMinimumFractionDigits(0);
String expected = "0.805";
String result = nf.format(0.8055d);
System.out.println("Should print (3 sig.fig.) " + expected + " got "
+ result
+ " - correct? = " + (expected.equals(result)));
nf.setMaximumFractionDigits(2);
double test = 12.345;
expected = "12.34";
result = nf.format(test);
System.out.println("Should print (2 sig.fig.) " + expected + " got "
+ result
+ " - correct? = " + (expected.equals(result)));
}
} Under Java 7, I get this:
But under Java 8:
i.e. they have fixed the first case, but broken the second one. |
In that case I suppose we could pick a different number for the unit test (that does round the same on Java 6 to 8) to close this issue. |
Yes, I'll also file a bug report with Oracle, but it's not worth holding up development for this as it's rather superficial I think. |
Just annoying when unit tests fail for no good reason. I'll submit a pull request with a less edgy test case. |
Fixes issue iipc#31 which relates to changes in how Java rounds doubles in some edge cases.
Possibly an issue with Java 8.
The unit test fails when using JDK 1.8.
12.345
should be rounded to12.34
but is rounded to12.35
instead.At first I thought the default rounding mode had been changed, but even setting it explicitly did not resolve the issue.
Not sure of the impact, but it is a little troubling that the same input could give different output based on whether you are using Java 8 or Java 7 to run the program.
The text was updated successfully, but these errors were encountered: