/** * Format a number supplied as a decimal * * @param dval the decimal value * @param fsb the FastStringBuffer to contain the result */ private void formatDecimal(BigDecimal dval, FastStringBuffer fsb) { dval = dval.setScale(maxFractionPartSize, BigDecimal.ROUND_HALF_EVEN); DecimalValue.decimalToString(dval, fsb); int point = fsb.indexOf('.'); int intDigits; if (point >= 0) { int zz = maxFractionPartSize - minFractionPartSize; while (zz > 0) { if (fsb.charAt(fsb.length() - 1) == '0') { fsb.setLength(fsb.length() - 1); zz--; } else { break; } } intDigits = point; if (fsb.charAt(fsb.length() - 1) == '.') { fsb.setLength(fsb.length() - 1); } } else { intDigits = fsb.length(); if (minFractionPartSize > 0) { fsb.append('.'); for (int i = 0; i < minFractionPartSize; i++) { fsb.append('0'); } } } if (minWholePartSize == 0 && intDigits == 1 && fsb.charAt(0) == '0') { fsb.removeCharAt(0); } else { fsb.prependRepeated('0', minWholePartSize - intDigits); } }
/** * Format a number supplied as a integer * * @param value the integer value * @param fsb the FastStringBuffer to contain the result */ private void formatInteger(NumericValue value, FastStringBuffer fsb) { fsb.append(value.getStringValueCS()); int leadingZeroes = minWholePartSize - fsb.length(); fsb.prependRepeated('0', leadingZeroes); if (minFractionPartSize != 0) { fsb.append('.'); for (int i = 0; i < minFractionPartSize; i++) { fsb.append('0'); } } }