|
[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
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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








