gives 12345678911234570640 as ...">

XSLT format number issue () with a lot

<xsl:value-of select="format-number(12345678911234567891,'0')"/> 

      

gives 12345678911234570640 as a result instead of 12345678911234567891.

It works for a number with max. 15 digits .eg

<xsl:value-of select="format-number(999999999999999,'0')"/>

      

gives exactly 999999999999999.

Why was the number changed? What would be the solution to display it as it is?

+3


source to share


3 answers


Since you are using Java, you might consider moving to Saxon 9 as your XSLT 2.0 processor and leveraging the type support xs:decimal

in XSLT / XPath 2.0:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs">

  <xsl:template match="data">
      <xsl:value-of select="format-number(xs:decimal(.), '0')"/>
  </xsl:template>

</xsl:transform>

      

while the input



<data>12345678911234567891</data>

      

outputs 12345678911234567891

.

+1


source


First, it depends on whether you are using XSLT 1.0 or 2.0.

XSLT 1.0 has only one numeric type (double precision floating point), and it is not capable of representing your long integer accurately.



In XSLT 2.0, your value is an integer, and all implementations are required to support integers up to 18 digits. Your integer has 20 digits, so you might see some differences between implementations.

Saxon handles "unlimited" integers (that is, you are likely to run out of memory before it reports that an integer has too many digits).

+1


source


This is due to floating point rounding. The IEEE754 floating point double is not capable of distinguishing the two numbers.

12345678911234570640

is the one that appears to be exactly floating point, so the one that you get back.

15 significant digits is the precision limit of double floating point, so it works in this case.

0


source







All Articles