我可以将此问题归类到
java.text.DigitList522行。
这种情况是,它认为十进制数字
6.0289已经舍入(与等效
BigDecimal表示形式相比是正确的
6.208899…),并决定不再舍入。问题在于,只有在舍入后的数字为的情况下才可以做出此决定
5,而不是大于的情况下才有意义
5。注意代码是如何
HALF_DOWN正确区分
digit=='5'和
digit>'5'情况。
显然,这是一个错误,并且由于一个事实,即执行类似正确操作(仅针对另一个方向)的代码恰好位于损坏的错误代码的下面,因此这是一个奇怪的错误。
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') { return true; } else if (digits[maximumDigits] == '5' ) { if (maximumDigits == (count - 1)) { // The rounding position is exactly the last index. if (allDecimalDigits || alreadyRounded) return false; else // Value was above the tie, we must round up. return true; } // We must round up if it gives a non null digit after '5'. for (int i=maximumDigits+1; i<count; ++i) { if (digits[i] != '0') { return true; } } } break;另一个数字没有发生这种情况的原因不是
6.2088四舍五入的结果(再次与
BigDecimal输出进行比较
6.208800…)。因此,在这种情况下它将四舍五入。



