--- old/src/java.base/share/classes/java/text/DigitList.java 2014-10-02 16:43:43.111800475 +0200
+++ new/src/java.base/share/classes/java/text/DigitList.java 2014-10-02 16:43:42.979800472 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -309,6 +309,7 @@
private void set(boolean isNegative, String s,
boolean roundedUp, boolean allDecimalDigits,
int maximumDigits, boolean fixedPoint) {
+
this.isNegative = isNegative;
int len = s.length();
char[] source = getDataChars(len);
@@ -382,7 +383,8 @@
// Round up if appropriate.
round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits,
roundedUp, allDecimalDigits);
- }
+
+ }
/**
* Round the representation to the given number of digits.
@@ -440,6 +442,9 @@
* count-1
. If 0, then all digits are rounded away, and
* this method returns true if a one should be generated (e.g., formatting
* 0.09 with "#.#").
+ * @param alreadyRounded Boolean indicating if rounding up already happened.
+ * @param allDecimalDigits Boolean indicating if the digits provide an exact
+ * representation of the value.
* @exception ArithmeticException if rounding is needed with rounding
* mode being set to RoundingMode.UNNECESSARY
* @return true if digit maximumDigits-1
should be
@@ -520,42 +525,47 @@
}
break;
case HALF_UP:
- if (digits[maximumDigits] >= '5') {
- // We should not round up if the rounding digits position is
- // exactly the last index and if digits were already rounded.
- if ((maximumDigits == (count - 1)) &&
- (alreadyRounded))
- return false;
-
- // Value was exactly at or was above tie. We must round up.
- return true;
- }
- break;
case HALF_DOWN:
if (digits[maximumDigits] > '5') {
+ // Value is above tie ==> must round-up
return true;
- } else if (digits[maximumDigits] == '5' ) {
- if (maximumDigits == (count - 1)) {
- // The rounding position is exactly the last index.
- if (allDecimalDigits || alreadyRounded)
- /* FloatingDecimal rounded up (value was below tie),
- * or provided the exact list of digits (value was
- * an exact tie). We should not round up, following
- * the HALF_DOWN rounding rule.
- */
- return false;
- else
- // Value was above the tie, we must round up.
- return true;
+ }
+ else if (digits[maximumDigits] == '5') {
+ // Digit at rounding position is a '5'. Tie cases.
+ if (maximumDigits != (count - 1)) {
+ // There are remaining digits. Above tie => must round-up
+ return true;
}
-
- // We must round up if it gives a non null digit after '5'.
- for (int i=maximumDigits+1; i round-up
+ return true;
+ }
+ else {
+ // Strictly follow HALF_DOWN rule ==> don't round-up
+ return false;
+ }
+ }
+ else {
+ // Not an exact binary representation.
+ if (alreadyRounded) {
+ // Digit sequence rounded-up. Was below tie.
+ // Don't round-up twice !
+ return false;
+ }
+ else {
+ // Digit sequence truncated. Was above tie.
+ // must round-up !
+ return true;
+ }
}
}
}
+ // Digit at rounding position is < '5' ==> no round-up.
+ // Just let do the default, which is no round-up (thus break).
break;
case HALF_EVEN:
// Implement IEEE half-even rounding