Supported Platforms
decimal-format
Syntax
decimal-format format-name { decimal-separator character; digit character ; grouping-separator character; infinity string; minus-sign character; nan string; pattern-separator character; percent character; per-mille character; zero-digit character; }
Release Information
Statement introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.
Description
Define formatting parameters for use by the format-number() XPath function. The decimal-format statement must be defined as a top-level statement in the script.
Attributes
decimal-format format-name | — | Decimal-format identifier, which is passed as the third argument to the format-number() XPath function. |
decimal-separator character | — | Character used as the decimal sign. The default is the period (.). |
digit character | — | Character used to represent a digit in a pattern. The default is the number sign (#). |
grouping-separator character | — | Character used as the digit group separator or the thousands separator. The default is the comma (,). |
infinity string | — | String used to represent infinity. The default is "Infinity". |
minus-sign character | — | Character used as the minus sign. The default is the hyphen (-). |
nan string | — | String used to represent NaN. The default is "NaN". |
pattern-separator character | — | Character used to separate patterns. The first pattern is used for positive numbers, and the second pattern is used for negative numbers. The default is the semicolon (;). |
percent character | — | Character used as the percent sign. The default is the percent character (%). |
per-mille character | — | Character used as a per mille sign. The default is the Unicode per mille sign (\x2030 or ‰). |
zero-digit character | — | Character used as zero. The default is the number zero (0). |
SLAX Example
The following code snippet lists the defaults for the decimal-format parameters, and uses the defined decimal format in the format-number XPath function:
version 1.1; decimal-format default-format { decimal-separator "." ; digit "#" ; grouping-separator "," ; infinity "Infinity" ; minus-sign "-" ; nan "NaN"; pattern-separator ";" ; percent "%"; per-mille "\x2030"; zero-digit "0" ; } match / { ... var $number = -14560302.5; expr format-number($number, "###,###.00", "default-format"); } /* output is -14,560,302.50 */
XSLT Equivalent
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:decimal-format name="default-format" decimal-separator="." digit="#" grouping-separator="," infinity="Infinity" minus-sign="-" NaN="NaN" pattern-separator=";" percent="%" per-mille="\x2030" zero-digit="0"/> <xsl:template match="/"> <xsl:variable name="number" select="-14560302.5"/> <xsl:value-of select="format-number($number, '###,###.00', 'default-format')"/> </xsl:template> </xsl:stylesheet>