DIGIFORMS
Digiforms Designer Documentation
 
 
 
 
 
 
Help by samples
 
 
 
Capture or output data in a defined layout
 
Extensible Markup Language
Formatting numbers
XSLT format-number() Function
Usage
The format-number() function is used to convert a number into a string
Syntax
string format-number( number, format, [ decimalformat ] )
xslt
Parameters
  • number
    Required. Specifies the number to be formatted
  • format
    Required. Specifies the format pattern. Here are some of the characters used in the formatting pattern:•0 (Digit)•# (Digit, zero shows as absent)•. (The position of the decimal point Example: ###.##)•, (The group separator for thousands. Example: ###,###.##)•% (Displays the number as a percentage. Example: ##%)•; (Pattern separator. The first pattern will be used for positive numbers and the second for negative numbers)
Examples
If you want to format output of numbers in a specific way, XSLT allow this using the format-number function. The format-number() function takes 3 parameters ( 2 mandatory and one optional ) Consider the following example:
<xsl:value-of select="125000.3333"></xsl:value> Output: 125000.3333
xslt
If you want to format this output with grouping separators, or control the number of decimals, apply formatting by using the format-number function
<xsl:value-of select="format-number(125000.3333,'###,###.00')"></xsl:value> Output: 125,000.33
xslt
In the above example, format-number uses the default XSLT number-format to: 1. Output numbers '#' 2. Separate groups of 3 digits ',' 3. Specify 2 decimal number to be outputted only '.00'
Formatting numbers with European grouping and decimal separators
<xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' ></xsl:decimal> <xsl:value-of select="format-number(24535.2, '###.###,00', 'european')"></xsl:value>
xslt
Formatting numbers to ensure correct number of digits Often month is represented as a single digit, eg. '4' for April, but when dealing with fixed-position formats, we often want to Express this as '04'.
<xsl:value-of Select="format-number(@month,'00')"/>
xslt
Removing unwanted decimals in whole number
<xsl:value-of select="format-number('4.0','#')"/>