net.sf.saxon.functions

Class FormatNumber2

public class FormatNumber2 extends SystemFunction implements XSLTFunction

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(StaticContext env)
StringevaluateAsString(XPathContext context)
Evaluate in a context where a string is wanted
ItemevaluateItem(XPathContext c)
Evaluate in a general context
voidfixup(DecimalSymbols dfs)
Fixup: this is a callback from the DecimalFormatManager used once the xsl:decimal-format element is identified
ExpressionpreEvaluate(StaticContext env)
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(StaticContext env)

evaluateAsString

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

evaluateItem

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

fixup

public void fixup(DecimalSymbols dfs)
Fixup: this is a callback from the DecimalFormatManager used once the xsl:decimal-format element is identified

preEvaluate

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