No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Travis Burtrum 2487a2f038 Add download link and maven info 4 years ago
src/main/java/com/moparisthebest/text First useable commit 4 years ago
.gitignore Initial commit with no changes to jdk classes 4 years ago
LICENSE Initial commit with no changes to jdk classes 4 years ago
pom.xml [maven-release-plugin] prepare for next development iteration 4 years ago
readme.md Add download link and maven info 4 years ago

readme.md

Java 7 DecimalFormat

If you upgrade to Java 8 you may be bit by this bug fix. A temporary JVM-wide fix that works is to copy java/text/DigitList.class from Java 7’s rt.jar to Java 8’s rt.jar, but who wants to run that way forever?

This project takes GPLv2 code from jdk7 and jdk8 to create a class that extends DecimalFormat, but retains the old rounding behavior of Java 6 and 7.

This is the offending bug fix we are trying to revert, it only changes DigitList.java, but since it’s package private and not an interface, there is no way to just change it’s usages in only some instances of DecimalFormat, even with reflection. I took DecimalFormat.java and some classes it depends on from jdk8 and DigitList.java from jdk7, which you will find unchanged in the first commit. The changes I had to make to get everything to work are included in the second and subsequent commits.

To use this, replace your java.text.DecimalFormat usages with com.moparisthebest.text.DecimalFormat (or com.moparisthebest.text.OldDecimalFormat, they are the same). These classes are instances of java.text.DecimalFormat so only the constructors really need changed. com.moparisthebest.text.OldDecimalFormat has a main method that allows you to test various calculations and their output using the ‘correct’ method of BigDecimal for decimal math, and the two Decimalformat implementations, here is some example output:

$ /usr/lib/jvm/java-8-oracle/bin/java com.moparisthebest.text.OldDecimalFormat 50 0.0259 2
50 * 0.0259 with precision of 2:
java.math.BigDecimal:                  1.30
com.moparisthebest.text.DecimalFormat: 1.30
java.text.DecimalFormat:               1.29

Download

You can download this from maven central or of course just add it to your pom.xml:

<dependency>
    <groupId>com.moparisthebest.text</groupId>
    <artifactId>java7decimalformat</artifactId>
    <version>1.0</version>
</dependency>

License

By necessity, this must inherit the license Sun/Oracle provided the classes under, which is GPLv2 only, the headers in the classes are unchanged. A copy of the full license is available in LICENSE.

This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.  Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.

This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).

You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.