MarkLogic 12 EA 1 Product Documentation
fn.formatNumber

fn.formatNumber(
   value as Number,
   picture as String,
   [decimal-format-name as String]
) as String

Summary

Returns a formatted string representation of value argument based on the supplied picture. An optional decimal format name may also be supplied for interpretation of the picture string. This is an XSLT function, and it is available in XSLT, XQuery 1.0-ml, and Server-Side JavaScript.

Parameters
value The given numeric $value that needs to be formatted.
picture The desired string representation of the given number $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the format-number picture string, see http://www.w3.org/TR/xslt20/#function-format-number.
decimal-format-name Represents a named <xsl:decimal-format> instruction. It is used to assign values to the variables mentioned above based on the picture string.

Example

fn.formatNumber(xs.integer("1000000"),"#,##0.00");
=>
1,000,000.00
 

Example

var stylesheet = fn.head(xdmp.unquote(
'<xsl:stylesheet version="2.0"\n\
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\n\
   xmlns:xs="http://www.w3.org/2001/XMLSchema">\n\
    <xsl:decimal-format name="testformat" decimal-separator="."/>\n\
    <xsl:template match="foo">\n\
      <xsl:sequence select="format-number(xs:float('
        + "'1234.5'), '#,##0.00', 'testformat')"
        + '"/>\n\
    </xsl:template>\n\
</xsl:stylesheet>'));
xdmp.xsltEval(stylesheet, fn.head(xdmp.unquote('<foo/>')));
=>
1,234.50
 
Powered by MarkLogic Server | Terms of Use | Privacy Policy