This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: number of digits
- To: mohamed dot itani at softsolutions dot fr
- Subject: Re: [xsl] number of digits
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Tue, 22 May 2001 05:45:05 -0700 (PDT)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
> Is there any xsl function or trick to get the number of digits of a
> certain number ??
The solution depends on the number system used to represent the number and whether
the number is a whole integer or not:
1. Decimal
string-length($x) - (contains($x, '.')) - (contains($x, '-'))
2. Hexadecimal integer
<digits:node>
<digit>0</digit>
<digit>16</digit>
<digit>256</digit>
<digit>4096</digit>
<digit>65536</digit>
<digit>1048576</digit>
<digit>16777216</digit>
<digit>268435456</digit>
<digit>4294967296</digit>
<digit>68719476736</digit>
<digit>1099511627776</digit>
<digit>17592186044416</digit>
<digit>281474976710656</digit>
<digit>4503599627370496</digit>
<digit>72057594037927936</digit>
<digit>1152921504606846976</digit>
</digits:node>
count($st/digits:node/digit[. > $x][1]/preceding-sibling::digit)
where the "st" variable is defined as:
<xsl:variable name="st" select="document('')/*"/>
3. Integer in another numeric system
The same as the above, only the "digits:node/digit" nodes should contain consecutive
powers of the base of the numeric system.
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list