Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1646

NumberUtils fails to create requested type for floating point zero

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 3.12.0
    • Fix Version/s: 3.13.0
    • Component/s: lang.math.*
    • Labels:
      None

      Description

      This currently fails:

              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0D"));
      

      This passes:

              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0.F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0.D"));
              assertEquals(Float.valueOf(0), NumberUtils.createNumber("0e0F"));
              assertEquals(Double.valueOf(0), NumberUtils.createNumber("0e0D"));
      

      This is due to the incorrect extraction of the mantissa for a floating point value when there is no exponent or decimal place as it includes the trailing format specifier (F or D). The input string is then not detected as being all zeros and the returned type is BigDecimal.

        Attachments

          Activity

            People

            • Assignee:
              aherbert Alex Herbert
              Reporter:
              aherbert Alex Herbert
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: