net.sf.saxon.functions

Class FormatNumber

Implemented Interfaces:
SequenceIterable, Serializable, EvaluableItem, InstructionInfoProvider, SourceLocator, XSLTFunction

public class FormatNumber
extends SystemFunction
implements XSLTFunction

XSLT 2.0 implementation of format-number() function - removes the dependence on the JDK.

Field Summary

Fields inherited from class net.sf.saxon.functions.SystemFunction

operation

Fields inherited from class net.sf.saxon.expr.FunctionCall

argument

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Method Summary

static BigDecimal
adjustToDecimal(double value, int precision)
Convert a double to a BigDecimal.
void
checkArguments(ExpressionVisitor visitor)
CharSequence
evaluateAsString(XPathContext context)
Evaluate in a context where a string is wanted
Item
evaluateItem(XPathContext c)
Evaluate in a general context
void
fixup(DecimalSymbols dfs)
Fixup: this is a callback from the DecimalFormatManager used once the xsl:decimal-format element is identified
Expression
preEvaluate(ExpressionVisitor visitor)
preEvaluate: this method suppresses compile-time evaluation by doing nothing.

Methods inherited from class net.sf.saxon.functions.SystemFunction

addContextDocumentArgument, addDocToPathMap, checkArguments, computeCardinality, computeSpecialProperties, copy, getDetails, getErrorCodeForTypeErrors, getItemType, getRequiredType, makeSystemFunction, optimize, setDetails, useContextItemAsDefault

Methods inherited from class net.sf.saxon.expr.FunctionCall

addExternalFunctionCallToPathMap, checkArgumentCount, checkArguments, equals, explain, getArguments, getDisplayName, getFunctionName, getNumberOfArguments, hashCode, iterateSubExpressions, optimize, preEvaluate, promote, replaceSubExpression, setArguments, setFunctionName, simplify, simplifyArguments, toString, typeCheck

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Method Details

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)
            throws XPathException
Overrides:
checkArguments in interface SystemFunction

evaluateAsString

public CharSequence evaluateAsString(XPathContext context)
            throws XPathException
Evaluate in a context where a string is wanted
Overrides:
evaluateAsString in interface Expression

evaluateItem

public Item evaluateItem(XPathContext c)
            throws XPathException
Evaluate in a general context
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Expression

fixup

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

preEvaluate

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