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>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--