Xslt Absolute Values

Getting the Absolute Value of a number using native Xslt functions

One way of doing it in Xslt 1.0.

Here is an example of one way of getting the Absolute Value of some amount in Xslt.  This uses format-number() to change the numerical value to a string, ignoring any negating hyphens.  Once done, number() is called to return to a numerical value.  

 

        <td>
          <!--  //    AbPErrDeadModel -->
          <xsl:value-of select="100 * number(format-number(($DeadZero - $DeadModel) div $DeadZero), '###0.0###;#')"/>
        </td>

 

In the format string, '###0.0###;#', the semi-colon separates the format patterns for positive and negative numbers. The second hash or pound or sharp symbol indicates a copy of the positive format, and no leading hyphen or other indication is defined for negative numbers, so they come out the same formatted string as positive numbers.

 

Check XHTML  «  feebdack.com  Copyright ©  Xander Lih  2000-2009   »  Check CSS