int32_t DigitFormatter::countChar32( const DigitGrouping &grouping, const DigitInterval &interval, const DigitFormatterOptions &options) const { int32_t result = interval.length(); // We always emit '0' in lieu of no digits. if (result == 0) { result = 1; } if (options.fAlwaysShowDecimal || interval.getLeastSignificantInclusive() < 0) { result += fDecimal.countChar32(); } result += grouping.getSeparatorCount(interval.getIntDigitCount()) * fGroupingSeparator.countChar32(); return result; }
DigitList & FixedPrecision::round( DigitList &value, int32_t exponent, UErrorCode &status) const { if (U_FAILURE(status)) { return value; } value .fContext.status &= ~DEC_Inexact; if (!fRoundingIncrement.isZero()) { if (exponent == 0) { value.quantize(fRoundingIncrement, status); } else { DigitList adjustedIncrement(fRoundingIncrement); adjustedIncrement.shiftDecimalRight(exponent); value.quantize(adjustedIncrement, status); } if (U_FAILURE(status)) { return value; } } int32_t leastSig = fMax.getLeastSignificantInclusive(); if (leastSig == INT32_MIN) { value.round(fSignificant.getMax()); } else { value.roundAtExponent( exponent + leastSig, fSignificant.getMax()); } if (fExactOnly && (value.fContext.status & DEC_Inexact)) { status = U_FORMAT_INEXACT_ERROR; } else if (fFailIfOverMax) { // Smallest interval for value stored in interval DigitInterval interval; value.getSmallestInterval(interval); if (fMax.getIntDigitCount() < interval.getIntDigitCount()) { status = U_ILLEGAL_ARGUMENT_ERROR; } } return value; }