} catch (XPathException e) {
value = new DoubleValue(value.getDoubleValue() * multiplier);
}
}
FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.TINY);
if (value instanceof DoubleValue || value instanceof FloatValue) {
BigDecimal dec = adjustToDecimal(value.getDoubleValue(), 2);
formatDecimal(dec, sb);
//formatDouble(value.getDoubleValue(), sb);
} else if (value instanceof IntegerValue) {
formatInteger(value, sb);
} else if (value instanceof DecimalValue) {
//noinspection RedundantCast
formatDecimal(((DecimalValue)value).getDecimalValue(), sb);
}
// System.err.println("Justified number: " + sb.toString());
// Map the digits and decimal point to use the selected characters
int[] ib = StringValue.expand(sb);
int ibused = ib.length;
int point = sb.indexOf('.');
if (point == -1) {
point = sb.length();
} else {
ib[point] = dfs.decimalSeparator;
// If there is no fractional part, delete the decimal point
if (maxFractionPartSize == 0) {
ibused--;
}
}
// Map the digits
if (dfs.zeroDigit != '0') {
int newZero = dfs.zeroDigit;
for (int i=0; i<ibused; i++) {
int c = ib[i];
if (c>='0' && c<='9') {
ib[i] = (c-'0'+newZero);
}
}
}
// Add the whole-part grouping separators
if (wholePartGroupingPositions != null) {
if (wholePartGroupingPositions.length == 1) {
// grouping separators are at regular positions
int g = wholePartGroupingPositions[0];
int p = point - g;
while (p > 0) {
ib = insert(ib, ibused++, dfs.groupingSeparator, p);
//sb.insert(p, unicodeChar(dfs.groupingSeparator));
p -= g;
}
} else {
// grouping separators are at irregular positions
for (int i=0; i<wholePartGroupingPositions.length; i++) {
int p = point - wholePartGroupingPositions[i];
if (p > 0) {
ib = insert(ib, ibused++, dfs.groupingSeparator, p);
//sb.insert(p, unicodeChar(dfs.groupingSeparator));
}
}
}
}
// Add the fractional-part grouping separators
if (fractionalPartGroupingPositions != null) {
// grouping separators are at irregular positions.
for (int i=0; i<fractionalPartGroupingPositions.length; i++) {
int p = point + 1 + fractionalPartGroupingPositions[i] + i;
if (p < ibused-1) {
ib = insert(ib, ibused++, dfs.groupingSeparator, p);
//sb.insert(p, dfs.groupingSeparator);
} else {
break;
}
}
}
// System.err.println("Grouped number: " + sb.toString());
//sb.insert(0, prefix);
//sb.insert(0, minusSign);
//sb.append(suffix);
FastStringBuffer res = new FastStringBuffer(prefix.length() + minusSign.length() + suffix.length() + ibused);
res.append(minusSign);
res.append(prefix);
res.append(StringValue.contract(ib, ibused));
res.append(suffix);
return res;
}