Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6548597

Wrong behaviour of the "format-number" function

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: xml

      Description

      Products: JDK 6, JAXP RI 1.4.

      According to XSLT specification (http://www.w3.org/TR/xslt#function-format-number):
      "The format pattern string is in the syntax specified by the JDK 1.1 DecimalFormat class. The format pattern string is in a localized notation: the decimal-format determines what characters have a special meaning in the pattern (with the exception of the quote character, which is not localized). The format pattern must not contain the currency sign (#x00A4); support for this feature was added after the initial release of JDK 1.1."
      It seems like current RI behaviour does not follow the syntax specified by the JDK 1.1 DecimalFormat class.
      It is not obvious for me whether transformer must report an error in case of pattern is incorrect or can it allow such a pattern with non-determined behaviour.
      The cases include:
      a) Currency sign is allowed by RI in the format pattern and produces meaningful output, e.g. <xsl:value-of select="format-number(95.4857,'&#164;###.####')"/> produces $95.4857.
      b) RI allows format patterns like "######.####", which is incorrect: first character before point must be zero like in "#####0.####".
      c) In case of presence of different subpatterns for positive and negative numbers, RI follows newer specification of patterns in DecimalFormat class.
      In JDK 6 it says:
      "If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)". "
      But there is no such sentence in JDK 1.1 documentation for DecimalFormat. Instead it says:
      "pattern := subpattern{;subpattern}
      subpattern := {prefix}integer{.fraction}{suffix}
      prefix := '\\u0000'..'\\uFFFD' - specialCharacters
      suffix := '\\u0000'..'\\uFFFD' - specialCharacters
      integer := '#'* '0'* '0'
      fraction := '0'* '#'*
      Notation:
       X* 0 or more instances of X
       (X | Y) either X or Y.
       X..Y any character from X up to Y, inclusive.
       S - T characters in S, except those in T
      The first subpattern is for positive numbers. The second (optional) subpattern is for negative numbers. (In both cases, ',' can occur inside the integer portion--it is just too messy to indicate in BNF.)"
      According to this:
      Output of <xsl:value-of select="format-number(-87504.4812,'00,0000.000###;#####,0.000###')"/>
      should be "8750,4.4812" instead of "-08,7504.4812".
      Output of <xsl:value-of select="format-number(-87504.4812,'00,0000.000###;-###,###.000###')"/>
      should be "-87,504.4812" instead of "-08,7504.4812".
      How to reproduce (all files are attached):
      run "java XSLTransform numberformat28.xml numberformat28.xsl"

      It seems like JAXP RI uses JDK DecimalFormat class, behavior of which was changed since JDK 1.1.

        Attachments

          Activity

            People

            • Assignee:
              joehw Joe Wang
              Reporter:
              ashurygisunw Alexey Shurygin (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: