[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Function that reduces the number of digits to the

Subject: Re: Function that reduces the number of digits to the right of the decimal point?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Jun 2020 16:53:24 -0000
 Re: Function that reduces the number of digits to the
Hi Folks,

Thank you for your excellent feedback!

Thank you Michael Kay for pointing out the round versus truncate issue. I
asked my customer which they want (round or truncate) and they want the option
of doing either. So I added a third argument to my function $round-or-truncate
and now the function can do either. Here is the updated function which
incorporates your suggestions:
--------------------------------------
<xsl:function name="f:reduce-number-of-digits-after-decimal-point">
    <xsl:param name="num" />
    <xsl:param name="desired-number-of-digits-after-decimal-point"
as="xs:integer" />
    <xsl:param name="round-or-truncate" as="xs:string" />

    <xsl:choose>
        <xsl:when test="$round-or-truncate eq 'round'">
            <xsl:value-of select="round($num,
$desired-number-of-digits-after-decimal-point)"/>
        </xsl:when>
        <xsl:when test="$round-or-truncate eq 'truncate'">
            <xsl:variable name="multiplication-factor"
select="xs:integer(math:pow(10,
$desired-number-of-digits-after-decimal-point))" as="xs:integer"/>
            <xsl:value-of select="($num*$multiplication-factor idiv 1) div
$multiplication-factor" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="error(xs:QName('round-or-truncate'),
'Invalid value for $round-or-truncate')"/>
        </xsl:otherwise>
    </xsl:choose>

</xsl:function>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.