Controller ctrl = context.getController();
DecimalFormatManager dfm = ctrl.getDecimalFormatManager();
DecimalFormatSymbols dfs;
AtomicValue av0 = (AtomicValue)argument[0].evaluateItem(context);
NumericValue number = (NumericValue)av0.getPrimitiveValue();
String format = argument[1].evaluateItem(context).getStringValue();
if (numArgs==2) {
dfs = dfm.getDefaultDecimalFormat();
} else {
String uri = dfURI;
String localName = dfLocalName;
if (localName==null) {
// the decimal-format name was given as a run-time expression
String qname = argument[2].evaluateItem(context).getStringValue();
if (!Name.isQName(qname)) {
DynamicError e = new DynamicError("Decimal format name '" + qname + "' is not a valid QName");
e.setXPathContext(context);
e.setErrorCode("XT1280");
throw e;
}
try {
String[] parts = Name.getQNameParts(qname);
localName = parts[1];
uri = nsContext.getURIForPrefix(parts[0], false);
if (uri==null) {
DynamicError e = new DynamicError("Namespace prefix '" + parts[0] + "' has not been defined");
e.setXPathContext(context);
e.setErrorCode("XT1280");
throw e;
}
} catch (QNameException e) {
dynamicError("Invalid decimal format name. " + e.getMessage(), "XT1280", context);
}
}
dfs = dfm.getNamedDecimalFormat(uri, localName);
if (dfs==null) {
DynamicError e = new DynamicError(
"format-number function: decimal-format '" + localName + "' is not defined");
e.setXPathContext(context);
e.setErrorCode("XT1280");
throw e;
}
}
return formatNumber(number.getDoubleValue(), format, dfs, context);
}