Sam
Sam

Reputation: 5260

exponential notation to integer notation XSLT2.0

IS it possible to change the following exponential notation to integer notation using XSLT 2.0.

2.0151109001E10 to 20151109001

I tried with

number(2.0151109001E10)

but it gives NaN as answer.

EDIT: XSLT:

<xsl:variable name="a" select="ss:Cell[$key]/ss:Data"/>
<xsl:variable name="b" select="string($a)"/>
<xsl:variable name="c" select="number($b)"/>

OUTPUT:

 <a>2.0151109001E10</a>
 <b>2.0151109001E10</b>
 <c>2.0151109001E10</c>

The following works out

<xsl:value-of select="xs:decimal(xs:double(translate($a, ',', '.')))"/>

Upvotes: 0

Views: 1622

Answers (3)

fafl
fafl

Reputation: 7385

You can use format-number:

format-number(2.0151109001E10, '#')

Upvotes: 0

michael.hor257k
michael.hor257k

Reputation: 117073

The real problem with your input is not the exponential notation, but the use of a comma as the decimal mark. XML only recognizes a period as the decimal mark.

Try something like:

<xsl:value-of select="xs:decimal(xs:double(translate($a, ',', '.')))"/>

or:

<xsl:value-of select="format-number(translate($a, ',', '.'), '0')"/>

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172528

You can try to put them inside the single quotes '' like this:

number('7.2345E7')

gives

72340000

Upvotes: 1

Related Questions