Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Number Formatting (1/2) >

Function format-number

Numbers can be formatted for output using format-number() function. The first argument to this function is the number to be formatted the second one is a picture string, which provides a recipe for the formatting. In the first example the picture string indicates that the number should have 2 digits after decimal point.

Digits are indicated either by "#" or "0"Characters. Please note the difference. If zeroes are used than the string is padded by 0 to the specified length.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <aaa>
                        <xsl:value-of  select="format-number(123456789.6543,'#.##')"/>
                  </aaa>
                  <bbb>
                        <xsl:value-of  select="format-number(123456789,'#.##')"/>
                  </bbb>
                  <ccc>
                        <xsl:value-of  select="format-number(123456789,'#.00')"/>
                  </ccc>
                  <ddd>
                        <xsl:value-of  select="format-number(123456.789,'#.00')"/>
                  </ddd>
                  <eee>
                        <xsl:value-of  select="format-number(12.789,'00000.0')"/>
                  </eee>
                  <fff>
                        <xsl:value-of  select="format-number(12.789,'#####.#')"/>
                  </fff>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <aaa>123456789.65</aaa>
      <bbb>123456789</bbb>
      <ccc>123456789.00</ccc>
      <ddd>123456.79</ddd>
      <eee>00012.8</eee>
      <fff>12.8</fff>


Previous chapter: Transforming strings with regular expressions
Next chapter: Sorting
Previous page: - - -
Next page: Grouping separator

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of stanton
internetusers


You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks ing suit and swim trunks