XSLT Decimal Places

Posted on 2007-08-10
Last Modified: 2013-11-18
Hi Experts

I have an xslt page that is doing some division, how do I limit the output to say 2 decimal places, or even not show anything after the DP at all.

I'm currently playing with this I found on the web, but cant no joy yet.

  <xs:restriction base="xs:decimal">
  <xs:fractionDigits value="2"/>

Question by:Andy Green
    LVL 60

    Accepted Solution

    use format number
            <xsl:value-of select="format-number(a div b, '0.00')"/>


    <xsl:stylesheet xmlns:xsl="" version="1.0">
        <xsl:template match="test">
            <xsl:value-of select="format-number(a div b, '0.00')"/>

    will yield 1.67



    LVL 60

    Expert Comment

    by:Geert Bormans
    note that you posted a part of an xml schema, not an xslt
    xml-schema is for validation only
    LVL 3

    Author Comment

    by:Andy Green
    Got it working thanks.

    LVL 60

    Expert Comment

    by:Geert Bormans

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now