XSLT function to convert a number in Scientific Notation to Decimal format

Sometimes a division operation in XSLT returns a float/double value in scientific notation.  If you need the decimal equivalent of the same then use the below function:

    <!– Converts numbers in Scientific Notation e.g. 6.15595432E8 to decimal –>     
    <xsl:function name=“fn:remove-scientific-notation”> 
        <xsl:param name=“attr” /> 
        <xsl:choose> 
            <xsl:when test=“matches($attr, ‘^\-?[\d\.,]*[Ee][+\-]*\d*$’)”> 
                <xsl:value-of 
                    select=“format-number(number($attr), ‘#0.#############’)”> 
                </xsl:value-of> 
            </xsl:when> 
            <xsl:otherwise> 
                <xsl:value-of select=“$attr”></xsl:value-of> 
            </xsl:otherwise> 
        </xsl:choose> 
    </xsl:function>

Advertisements
This entry was posted in XSLT and tagged , , . Bookmark the permalink.

2 Responses to XSLT function to convert a number in Scientific Notation to Decimal format

  1. Here is another implementation for conversion scientific numbers to decimal. This template doesnt’t use regular expression and is XSLT 1.0 compatible.

    http://www.orm-designer.com/article/xslt-convert-scientific-notation-to-decimal-number

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s