Uploaded image for project: 'MyFaces Trinidad'
  1. MyFaces Trinidad
  2. TRINIDAD-1678

TrNumberFormat.prototype.numberToString doesn't account for numbers represented via scientific notation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.2.12-core
    • 1.2.13-core
    • Components
    • None

    Description

      ISSUE:
      ----------

      Say we have a 22-digit number string "7777777777777777777777". When this is converted to object it becomes 7.777777777777777e+21. This confuses TrNumberFormat.prototype.numberToString, as the poor guy thinks he's dealing with a fractional number, when really it's a big ass integer.

      FIX:


      The solution is, when converting from object to string, we first convert the string from scientific notation to standard expanded notation before applying any other formatting. See TrNumberFormat.scientificToExpanded.

      Note that I also added a utility method TrNumberFormat.trimLeadingZeroes. This is preferable to the previous hack – parseInt(parseFloat(numberString)) – because parseInt fails to correctly parse numbers represented via scientific notation (e.g. 7.777e+21 becomes 7).

      TESTS:
      ----------

      Tested using the following:

      <af:inputText label="default" id="it1">
      <af:convertNumber maxFractionDigits="40"/>
      </af:inputText>

      Results:

      (1) "7777777777777777777777" -> 7.777777777777777e+21 -> "7,777,777,777,777,777,000,000"
      (2) "0.00000000000000000000123456" -> 1.23456e-21 -> "0.00000000000000000000123456"
      (3) "1234.567890123456789012" -> 1234.567890123457 -> "1,234.567890123457"

      When would this fix possibly be useful? See case (2) above. That's the only case where scientific notation is used AND we don't lose any precision.

      Attachments

        1. scientificNotation_1.2.12.2.patch
          4 kB
          Cale Scholl
        2. scientificNotation_trunk.patch
          4 kB
          Cale Scholl

        Activity

          People

            jeanne.waldman@oracle.com Jeanne Waldman
            cale.scholl Cale Scholl
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: