net.sf.saxon.functions

Class FormatNumber

public class FormatNumber extends SystemFunction

XSLT 2.0 implementation of format-number() function - removes the dependence on the JDK.
Method Summary
static BigDecimaladjustToDecimal(double value, int precision)
Convert a double to a BigDecimal.
voidcheckArguments(ExpressionVisitor visitor)
Expressioncopy()
Copy an expression.
CharSequenceevaluateAsString(XPathContext context)
Evaluate in a context where a string is wanted
ItemevaluateItem(XPathContext c)
Evaluate in a general context
ExpressionpreEvaluate(ExpressionVisitor visitor)
preEvaluate: this method suppresses compile-time evaluation by doing nothing.

Method Detail

adjustToDecimal

public static BigDecimal adjustToDecimal(double value, int precision)
Convert a double to a BigDecimal. In general there will be several BigDecimal values that are equal to the supplied value, and the one we want to choose is the one with fewest non-zero digits. The algorithm used is rather pragmatic: look for a string of zeroes or nines, try rounding the number down or up as approriate, then convert the adjusted value to a double to see if it's equal to the original: if not, use the original value unchanged.

Parameters: value the double to be converted precision 2 for a double, 1 for a float

Returns: the result of conversion to a double

checkArguments

public void checkArguments(ExpressionVisitor visitor)

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

evaluateAsString

public CharSequence evaluateAsString(XPathContext context)
Evaluate in a context where a string is wanted

evaluateItem

public Item evaluateItem(XPathContext c)
Evaluate in a general context

preEvaluate

public Expression preEvaluate(ExpressionVisitor visitor)
preEvaluate: this method suppresses compile-time evaluation by doing nothing. We can't evaluate early because we don't have access to the DecimalFormatManager.

Parameters: visitor the expression visitor