Menu

Bug candidate: format-number(0,'#.####')

Help
penguish
2009-05-27
2016-10-14
  • penguish

    penguish - 2009-05-27

    Saxon-B 9.1.0.6

    using format-number on zero results in an empty string.

    sample xml:
    <numbers>
    <test id="1">1.3</test>
    <test id="4">0.0</test>
    <test id="5">0</test>
    </numbers>

    XSLT test case:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="text"/>
    <xsl:template match="numbers">
    <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="test">
    <xsl:value-of select="concat('Original: ',text())"/>
    Format with #.#####
    '<xsl:value-of select="format-number(xs:double(.), '#.#####')"/>'
    </xsl:template>
    </xsl:stylesheet>

     
    • Michael Kay

      Michael Kay - 2009-05-27

      This result seems to be in accordance with the spec. Why do you think it is wrong?

      If you want at least one digit in the result, you should specify '0.######' or '0.0#####' or perhaps #.0####'

       
      • penguish

        penguish - 2009-05-27

        Aha. Another case of RTFM, sorry for the noise. I expected at least one digit in there, to reflect the fact that it was a number after all; it seems perverse to format a number and end up with nothing at all. I'll have to re-read your books...

         
  • Thomas Fischer

    Thomas Fischer - 2016-10-14

    You've made my day! 8-)